Sign in to follow this  
Followers 0
Ace08

Need Help with adding Strings

3 posts in this topic

#1 ·  Posted (edited)

Hi there i was able to replicate my problem with this script, i have these datas which i placed individualy inside an array these datas are strings so i need to convert them into numbers but it isnt showing the right answer.

Local $Samplearray[99]
$Header = "89226.37"
$SampleArray[0] =  "000000000000980.44"
$SampleArray[1] =  "000000000000075.59"
$SampleArray[2] =  "000000000001060.28"
$SampleArray[3] =  "000000000000300.00"
$SampleArray[4] =  "000000000000266.14"
$SampleArray[5] =  "000000000000794.14"
$SampleArray[6] =  "000000000000479.04"
$SampleArray[7] =  "000000000000176.74"
$SampleArray[8] =  "000000000000164.47"
$SampleArray[9] =  "000000000006621.00"
$SampleArray[10] =  "000000000000186.26"
$SampleArray[11] =  "000000000000118.60"
$SampleArray[12] =  "000000000000319.33"
$SampleArray[13] =  "000000000001193.35"
$SampleArray[14] =  "000000000000261.88"
$SampleArray[15] =  "000000000000399.20"
$SampleArray[16] =  "000000000005318.43"
$SampleArray[17] =  "000000000000701.00"
$SampleArray[18] =  "000000000000172.99"
$SampleArray[19] =  "000000000000718.56"
$SampleArray[20] =  "000000000000239.52"
$SampleArray[21] =  "000000000024761.00"
$SampleArray[22] =  "000000000000665.00"
$SampleArray[23] =  "000000000000653.15"
$SampleArray[24] =  "000000000000075.58"
$SampleArray[25] =  "000000000000532.25"
$SampleArray[26] =  "000000000001048.50"
$SampleArray[27] =  "000000000000980.44"
$SampleArray[28] =  "000000000000266.13"
$SampleArray[29] =  "000000000000281.07"
$SampleArray[30] =  "000000000000532.27"
$SampleArray[31] =  "000000000000266.14"
$SampleArray[32] =  "000000000001000.00"
$SampleArray[33] =  "000000000001676.50"
$SampleArray[34] =  "000000000000235.26"
$SampleArray[35] =  "000000000000691.95"
$SampleArray[36] =  "000000000000128.02"
$SampleArray[37] =  "000000000000106.40"
$SampleArray[38] =  "000000000001871.99"
$SampleArray[39] =  "000000000000048.03"
$SampleArray[40] =  "000000000002094.54"
$SampleArray[41] =  "000000000000905.90"
$SampleArray[42] =  "000000000000239.50"
$SampleArray[43] =  "000000000000239.50"
$SampleArray[44] =  "000000000000266.00"
$SampleArray[45] =  "000000000000186.30"
$SampleArray[46] =  "000000000000159.69"
$SampleArray[47] =  "000000000000900.60"
$SampleArray[48] =  "000000000000654.23"
$SampleArray[49] =  "000000000000665.25"
$SampleArray[50] =  "000000000000212.88"
$SampleArray[51] =  "000000000000452.40"
$SampleArray[52] =  "000000000000467.45"
$SampleArray[53] =  "000000000000467.45"
$SampleArray[54] =  "000000000002676.75"
$SampleArray[55] =  "000000000000022.36"
$SampleArray[56] =  "000000000001467.45"
$SampleArray[57] =  "000000000002000.00"
$SampleArray[58] =  "000000000000395.00"
$SampleArray[59] =  "000000000000666.00"
$SampleArray[60] =  "000000000000213.00"
$SampleArray[61] =  "000000000000262.00"
$SampleArray[62] =  "000000000000102.09"
$SampleArray[63] =  "000000000000266.13"
$SampleArray[64] =  "000000000000581.23"
$SampleArray[65] =  "000000000000133.06"
$SampleArray[66] =  "000000000000334.66"
$SampleArray[67] =  "000000000000585.46"
$SampleArray[68] =  "000000000000095.52"
$SampleArray[69] =  "000000000000102.19"
$SampleArray[70] =  "000000000000128.80"
$SampleArray[71] =  "000000000000281.40"
$SampleArray[72] =  "000000000000234.88"
$SampleArray[73] =  "000000000000817.69"
$SampleArray[74] =  "000000000000448.10"
$SampleArray[75] =  "000000000000208.64"
$SampleArray[76] =  "000000000000826.08"
$SampleArray[77] =  "000000000000053.00"
$SampleArray[78] =  "000000000000103.80"
$SampleArray[79] =  "000000000000009.05"
$SampleArray[80] =  "000000000000399.21"
$SampleArray[81] =  "000000000000159.68"
$SampleArray[82] =  "000000000000261.00"
$SampleArray[83] =  "000000000001200.00"
$SampleArray[84] =  "000000000000661.00"
$SampleArray[85] =  "000000000001592.50"
$SampleArray[86] =  "000000000000282.80"
$SampleArray[87] =  "000000000000266.10"
$SampleArray[88] =  "000000000000461.47"
$SampleArray[89] =  "000000000000399.20"
$SampleArray[90] =  "000000000000665.33"
$SampleArray[91] =  "000000000002327.56"
$SampleArray[92] =  "000000000000159.00"
$SampleArray[93] =  "000000000001858.68"
$SampleArray[94] =  "000000000000266.13"
$SampleArray[95] =  "000000000000133.07"
$SampleArray[96] =  "000000000000261.85"
$SampleArray[97] =  "000000000000368.30"
$SampleArray[98] =  "000000000000210.82"
local $Data
For $i = 0 to Ubound($SampleArray)
    $Data = $Data + $SampleArray[$i]
    msgbox(0,"Debug",Number($Header) & @CRLF & Number($SampleArray[$i]) & @CRLF & Number($Data))
Next

the answer should be 89226.37 but its giving me 89226.3700000001, i placed a messagebox inside the loop to see if the script adds 0 while summing them up together but what happens is on the 0~97 array the script adds them giving me only answers with 2 decimal places however on the last array(98) it gives me this :unsure: . i was thinking of using Round function till 2 decimal places but i just want to know if it has something to do with my script. Thanks

Edited by Ace08

Work smarter not harder.My First Posted Script: DataBase

Share this post


Link to post
Share on other sites



It is nothing to do with your script; it is to do with the fact that digital computers cannot exactly represent all numbers. If you used integers you would probably get the answer you expected but with real numbers you will rarely get the exactly correct result.

You could use Round($ans,10)


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Thanks a lot martin for the comment i'll just have to round it up then :unsure:


Work smarter not harder.My First Posted Script: DataBase

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0