tufanv Expert Licensed User Longtime User Mar 10, 2016 #1 Hello I am having a problem i cant find the reason. First pic shows my code and logs according to code: kwd1 is : 9.5379 in the logs kwd2 is : 9.6627 in the logs kwd is : something strange Question 1 : it must be 9,6003 according to calculations. why is it an interesitng number ? As you can see in the in the below pic i am using kwd2 to add to tableview. in the logs in the above pic kwd2 is : 9.6627 Now please check my code in below pic and later check what my app shows for kwd2 in release in third pic: Altough the kwd2 is 9.6627 it shows something very different in release mode. Can you help me about it. what am i missing here ?
Hello I am having a problem i cant find the reason. First pic shows my code and logs according to code: kwd1 is : 9.5379 in the logs kwd2 is : 9.6627 in the logs kwd is : something strange Question 1 : it must be 9,6003 according to calculations. why is it an interesitng number ? As you can see in the in the below pic i am using kwd2 to add to tableview. in the logs in the above pic kwd2 is : 9.6627 Now please check my code in below pic and later check what my app shows for kwd2 in release in third pic: Altough the kwd2 is 9.6627 it shows something very different in release mode. Can you help me about it. what am i missing here ?
Erel B4X founder Staff member Licensed User Longtime User Mar 11, 2016 #2 You should post the code with 'code' tags instead of a screenshot. This way we can copy it and post a modified version. Either use NumberFormat or use Log($"KWD: $1.2{kwd1}"$). Upvote 0
You should post the code with 'code' tags instead of a screenshot. This way we can copy it and post a modified version. Either use NumberFormat or use Log($"KWD: $1.2{kwd1}"$).
tufanv Expert Licensed User Longtime User Mar 11, 2016 #3 Erel said: You should post the code with 'code' tags instead of a screenshot. This way we can copy it and post a modified version. Either use NumberFormat or use Log($"KWD: $1.2{kwd1}"$). Click to expand... Sorry, What is the reason for it i want to learn =) while the logs shows good , with release it shows another thing. Also for example i use: Code: Copy kwd=NumberFormat((((txtkod.Text.SubString2(bas,bitir))+(txtkod.Text.SubString2(bas2,bitir2)))/2),0,5) numberformat here but it still shows many fractions altough it must show five Upvote 0
Erel said: You should post the code with 'code' tags instead of a screenshot. This way we can copy it and post a modified version. Either use NumberFormat or use Log($"KWD: $1.2{kwd1}"$). Click to expand... Sorry, What is the reason for it i want to learn =) while the logs shows good , with release it shows another thing. Also for example i use: Code: Copy kwd=NumberFormat((((txtkod.Text.SubString2(bas,bitir))+(txtkod.Text.SubString2(bas2,bitir2)))/2),0,5) numberformat here but it still shows many fractions altough it must show five
tufanv Expert Licensed User Longtime User Mar 11, 2016 #4 Also for kwd value i changed the code with numberformat everywhere : Code: Copy kwd=NumberFormat((((NumberFormat(txtkod.Text.SubString2(bas,bitir),0,4))+(NumberFormat(txtkod.Text.SubString2(bas2,bitir2),0,4)))/2),0,5) but it is still giving : KWD: 9.600300000000001 Upvote 0
Also for kwd value i changed the code with numberformat everywhere : Code: Copy kwd=NumberFormat((((NumberFormat(txtkod.Text.SubString2(bas,bitir),0,4))+(NumberFormat(txtkod.Text.SubString2(bas2,bitir2),0,4)))/2),0,5) but it is still giving : KWD: 9.600300000000001
JanPRO Well-Known Member Licensed User Longtime User Mar 12, 2016 #5 Can you upload a demo project? Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Mar 13, 2016 #6 tufanv said: What is the reason for it i want to learn =) Click to expand... The proper way to convert a floating number to string is with NumberFormat (or the smart string literal). Otherwise any small rounding error can cause the number to show with many fraction digits. Note that the code you posted in post #4 is incorrect. You only need to use NumberFormat in the place where you convert the number to string. Upvote 0
tufanv said: What is the reason for it i want to learn =) Click to expand... The proper way to convert a floating number to string is with NumberFormat (or the smart string literal). Otherwise any small rounding error can cause the number to show with many fraction digits. Note that the code you posted in post #4 is incorrect. You only need to use NumberFormat in the place where you convert the number to string.
tufanv Expert Licensed User Longtime User Mar 13, 2016 #7 so i must do the calculations and finish them an at the end i must use numberformat right ? Erel said: The proper way to convert a floating number to string is with NumberFormat (or the smart string literal). Otherwise any small rounding error can cause the number to show with many fraction digits. Note that the code you posted in post #4 is incorrect. You only need to use NumberFormat in the place where you convert the number to string. Click to expand... Upvote 0
so i must do the calculations and finish them an at the end i must use numberformat right ? Erel said: The proper way to convert a floating number to string is with NumberFormat (or the smart string literal). Otherwise any small rounding error can cause the number to show with many fraction digits. Note that the code you posted in post #4 is incorrect. You only need to use NumberFormat in the place where you convert the number to string. Click to expand...
Erel B4X founder Staff member Licensed User Longtime User Mar 13, 2016 #8 Yes. Or use the code I posted in post #2. Upvote 0
tufanv Expert Licensed User Longtime User Jun 28, 2016 #9 I am still having problem at this. I have some doubles at my databae with at most 2 decimal points like 403.45 When i use httpjob and retrieve them and add them to table with numberformat(m.get("number"),0,2) i get too many decimal points like : 72.9300000000000000001 How can i fix this = I want to use numberformat to round them to 2 decimal points. edit: only solution i oculd find is i declared the numbers as string instead of double Upvote 0
I am still having problem at this. I have some doubles at my databae with at most 2 decimal points like 403.45 When i use httpjob and retrieve them and add them to table with numberformat(m.get("number"),0,2) i get too many decimal points like : 72.9300000000000000001 How can i fix this = I want to use numberformat to round them to 2 decimal points. edit: only solution i oculd find is i declared the numbers as string instead of double
Erel B4X founder Staff member Licensed User Longtime User Jun 28, 2016 #10 You are not using NumberFormat correctly. You should use it whenever you want to show the number to the user. Upvote 0
You are not using NumberFormat correctly. You should use it whenever you want to show the number to the user.
tufanv Expert Licensed User Longtime User Mar 14, 2017 #11 Erel said: You are not using NumberFormat correctly. You should use it whenever you want to show the number to the user. Click to expand... I am still having problems with these. I use numberformat2 when I want to show the text to user ( at the end ) my code is : Code: Copy jpy=1/m.Get("last")*100 fiyat(4).Text=NumberFormat2(jpy,0,5,5,False) & " TRY" this still gives me many fractions , more than 5 altough i set it to maximum 5 with numberformat2 . Am I using it wrong again ? (edit : also if the m.get("last") is 3.4545 lets say, numberformat2 with minimum fractions 5 does not give me 3.45450 but stil 3.4545 how can i fix that too ) Upvote 0
Erel said: You are not using NumberFormat correctly. You should use it whenever you want to show the number to the user. Click to expand... I am still having problems with these. I use numberformat2 when I want to show the text to user ( at the end ) my code is : Code: Copy jpy=1/m.Get("last")*100 fiyat(4).Text=NumberFormat2(jpy,0,5,5,False) & " TRY" this still gives me many fractions , more than 5 altough i set it to maximum 5 with numberformat2 . Am I using it wrong again ? (edit : also if the m.get("last") is 3.4545 lets say, numberformat2 with minimum fractions 5 does not give me 3.45450 but stil 3.4545 how can i fix that too )
Erel B4X founder Staff member Licensed User Longtime User Mar 14, 2017 #12 Please reproduce it in a small project and upload it. Upvote 0
tufanv Expert Licensed User Longtime User Feb 10, 2018 #13 Erel said: Please reproduce it in a small project and upload it. Click to expand... I am still having this problem after many months. I can't reproduce it for a small project as numbers are constantly changing every second. I can't find the solution. As you said , I am only using the numberformat when converting my double to string with: Code: Copy lblbtcprofit(sayi).Text="+ % " &NumberFormat(((currentprice-averagecost)/averagecost*100),1,1) and someitmes when numbers change I get %88.69999999999999... using the same code with log( it shows : %88.7 . it is really interesting and bothering. Last edited: Feb 10, 2018 Upvote 0
Erel said: Please reproduce it in a small project and upload it. Click to expand... I am still having this problem after many months. I can't reproduce it for a small project as numbers are constantly changing every second. I can't find the solution. As you said , I am only using the numberformat when converting my double to string with: Code: Copy lblbtcprofit(sayi).Text="+ % " &NumberFormat(((currentprice-averagecost)/averagecost*100),1,1) and someitmes when numbers change I get %88.69999999999999... using the same code with log( it shows : %88.7 . it is really interesting and bothering.
Erel B4X founder Staff member Licensed User Longtime User Feb 11, 2018 #14 You can check the string length and do something if it is longer than you expected. Upvote 0
tufanv Expert Licensed User Longtime User Feb 12, 2018 #15 Erel said: You can check the string length and do something if it is longer than you expected. Click to expand... I am checking them but they are randomly happening like for example I type 0.00004534 into textbox and add it to keyvaluestore , it is recorded as 0.00004534000000000001 or sometimes 0.00004534999999999999 it is really hard to check this for every entry and fix it . if it was a standard number everytime i could replace it with null but it changes every time it also messes up the cost calculations. This only happens at number with big fractions like 0.00003234 . cant find a proper way to fix this . Do you have a suggestion ? Upvote 0
Erel said: You can check the string length and do something if it is longer than you expected. Click to expand... I am checking them but they are randomly happening like for example I type 0.00004534 into textbox and add it to keyvaluestore , it is recorded as 0.00004534000000000001 or sometimes 0.00004534999999999999 it is really hard to check this for every entry and fix it . if it was a standard number everytime i could replace it with null but it changes every time it also messes up the cost calculations. This only happens at number with big fractions like 0.00003234 . cant find a proper way to fix this . Do you have a suggestion ?
Erel B4X founder Staff member Licensed User Longtime User Feb 13, 2018 #16 Maybe I didn't understand your previous post. It is expected that a double number will not be 100% accurate. This is why you should always use NumberFormat when you convert it to a string. For 100% accurate decimal numbers: https://www.b4x.com/android/forum/t...umber-similar-to-b4a-bignumber.79332/#content You will need to convert the numbers to strings before you store them in the database. Upvote 0
Maybe I didn't understand your previous post. It is expected that a double number will not be 100% accurate. This is why you should always use NumberFormat when you convert it to a string. For 100% accurate decimal numbers: https://www.b4x.com/android/forum/t...umber-similar-to-b4a-bignumber.79332/#content You will need to convert the numbers to strings before you store them in the database.
tufanv Expert Licensed User Longtime User Feb 13, 2018 #17 Erel said: Maybe I didn't understand your previous post. It is expected that a double number will not be 100% accurate. This is why you should always use NumberFormat when you convert it to a string. For 100% accurate decimal numbers: https://www.b4x.com/android/forum/t...umber-similar-to-b4a-bignumber.79332/#content You will need to convert the numbers to strings before you store them in the database. Click to expand... That looks good ! I will try it . Thanks Upvote 0
Erel said: Maybe I didn't understand your previous post. It is expected that a double number will not be 100% accurate. This is why you should always use NumberFormat when you convert it to a string. For 100% accurate decimal numbers: https://www.b4x.com/android/forum/t...umber-similar-to-b4a-bignumber.79332/#content You will need to convert the numbers to strings before you store them in the database. Click to expand... That looks good ! I will try it . Thanks