How do you go about rounding a decimal in B4A? I have a percent that is being calculated in my app and I just want it to be like: xx.x% instead of something crazy like 98.388888767. I do want to keep the first number after the decimal so the example would become 98.4%
How do you go about rounding a decimal in B4A? I have a percent that is being calculated in my app and I just want it to be like: xx.x% instead of something crazy like 98.388888767. I do want to keep the first number after the decimal so the example would become 98.4%
I can't seem to find a function in core for the old VB6 Int() function.
I.e if I have a double say 5.57 the old VB6 Int(5.57) will yield 5
Both B4A Round functions will yield 6 or 6.nn depending on whether you used Round2 with n number of decimal places etc.
Is there a similar function to just truncate off all the decimal places and take just the whole number?
Yes, Floor(x) is equivalent to VB6 Int(x).
In Java Int is the keyword for Integer.
You have also a Ceil(x) function.
With your example
Floor(5.57) = 5
Ceil(5.57) = 6
Floor(-5.57) = -6
Ceil(-5.57) = -5
Best regards.
Yes, Floor(x) is equivalent to VB6 Int(x).
In Java Int is the keyword for Integer.
You have also a Ceil(x) function.
With your example
Floor(5.57) = 5
Ceil(5.57) = 6
Floor(-5.57) = -6
Ceil(-5.57) = -5
Best regards.
Just for clarity, "rounding" has been a debate for some time. Have a look at the thread linked below.
The simple answer is, for rounding numbers NumberFormat2 is the correct solution. Erel has been hammering this for sometime even though it took me sometime to catch on he is of course correct.
Round2 is not "technically" correct although for most common uses is close enough.
For obtaining the integer part only Floor and Ceiling are the way to go.