Filippo Expert Licensed User Longtime User Dec 20, 2024 #1 Hi, in B4a this code works without a problem, in B4i the app crashes. Please fix the error. B4X: Copy Log("NumberFormat2=" & NumberFormat2(-0.0120000000000009, 1, 1, 1, False)) Dim dbl As Double = NumberFormat2(-0.0120000000000009, 1, 1, 1, False) Log("dbl=" & dbl) ) B4a-Log: NumberFormat2=-0.0 dbl=-0 Click to expand... B4i-Log: NumberFormat2=-0.0 Error occurred on line: 571 (Main) Cannot parse: -0.0 Click to expand...
Hi, in B4a this code works without a problem, in B4i the app crashes. Please fix the error. B4X: Copy Log("NumberFormat2=" & NumberFormat2(-0.0120000000000009, 1, 1, 1, False)) Dim dbl As Double = NumberFormat2(-0.0120000000000009, 1, 1, 1, False) Log("dbl=" & dbl) ) B4a-Log: NumberFormat2=-0.0 dbl=-0 Click to expand... B4i-Log: NumberFormat2=-0.0 Error occurred on line: 571 (Main) Cannot parse: -0.0 Click to expand...
Erel B4X founder Staff member Licensed User Longtime User Dec 22, 2024 #2 Fixed for the next update. (Note that there is no reason to use NumberFormat here)
Filippo Expert Licensed User Longtime User Dec 22, 2024 #3 Erel said: Fixed for the next update. Click to expand... Thank you! Erel said: (Note that there is no reason to use NumberFormat here) Click to expand... How would you do it?
Erel said: Fixed for the next update. Click to expand... Thank you! Erel said: (Note that there is no reason to use NumberFormat here) Click to expand... How would you do it?
Erel B4X founder Staff member Licensed User Longtime User Dec 22, 2024 #4 Filippo said: How would you do it? Click to expand... What exactly are you trying to do? To round the number?
Filippo said: How would you do it? Click to expand... What exactly are you trying to do? To round the number?
Filippo Expert Licensed User Longtime User Dec 22, 2024 #5 Erel said: What exactly are you trying to do? To round the number? Click to expand... I only need the number with a maximum of one decimal place.
Erel said: What exactly are you trying to do? To round the number? Click to expand... I only need the number with a maximum of one decimal place.
Erel B4X founder Staff member Licensed User Longtime User Dec 22, 2024 #6 In most cases you should simply keep the number as-is. The rounding should be done when you show the number - at that point you convert it to a string with NumberFormat. Double numbers cannot 100% represent decimal numbers anyway. You aren't really keeping a number with one decimal place (at least not in all cases).
In most cases you should simply keep the number as-is. The rounding should be done when you show the number - at that point you convert it to a string with NumberFormat. Double numbers cannot 100% represent decimal numbers anyway. You aren't really keeping a number with one decimal place (at least not in all cases).
E emexes Expert Licensed User Longtime User Dec 22, 2024 #7 Erel said: Double numbers cannot 100% represent decimal numbers anyway. Click to expand... Double numbers cannot 100% represent (most) decimal fractions anyway. Binary fractions eg 1/2 1/4 1/8 1/16 etc eg 0.125 0.25 0.375 0.5 0.625 0.75 0.875 etc are no problem. Non-binary fractions eg 1/3 1/5 1/6 1/7 1/9 1/10 etc can be a problem (but usually they're close enough to act and display as you'd expect).
Erel said: Double numbers cannot 100% represent decimal numbers anyway. Click to expand... Double numbers cannot 100% represent (most) decimal fractions anyway. Binary fractions eg 1/2 1/4 1/8 1/16 etc eg 0.125 0.25 0.375 0.5 0.625 0.75 0.875 etc are no problem. Non-binary fractions eg 1/3 1/5 1/6 1/7 1/9 1/10 etc can be a problem (but usually they're close enough to act and display as you'd expect).