Android Question NumberFormat2 round number calculate

Eugenio

Member
Licensed User
Longtime User
Hello

I created a calculation and the result obtained using NumberFormat does not correspond to the calculator display.

Example: 0.5 x 229.45 = 114.725

When I use two decimal places the calculator the result is 114.73

But when I use NumberFormat2 as follows:

MyCalc = 0.5 x 229.45
MyResult = 114.725

Edit1.Text=NumberFormat2(MyResult, 0,2,2, False)
or
Edit1.Text NumberFormat2(MyResult, 0,2,2, True)

I have the same result for True and False, when the correct 114.72 would be 114.73

Thanks all.
 

klaus

Expert
Licensed User
Longtime User
What do you expect ?
The rounding of 114.725 is allways 114.73 !
And 114.724 gives 114.72 !
In the NumberFormat2(MyResult, 0,2,2, True) the last parameter is the grouping parameter which means:
True > 120,000.00
False > 120000.00
 
Upvote 0

Eugenio

Member
Licensed User
Longtime User
What do you expect ?
The rounding of 114.725 is allways 114.73 !
And 114.724 gives 114.72 !
In the NumberFormat2(MyResult, 0,2,2, True) the last parameter is the grouping parameter which means:
True > 120,000.00
False > 120000.00


Klaus

Thanks for the quick response.

However what I'm not getting exactly what you described.

I have a value of 114.725 and would round it to 114.73.

But when I use NumberFormat2 the returned value is 114.72.

And it should be 114.73

This is my difficulty.

Maybe I have not been very clear in my previous question.

There is another way to round values?

Thank you again!
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Klaus

Thanks for the quick response.

However what I'm not getting exactly what you described.

I have a value of 114.725 and would round it to 114.73.

But when I use NumberFormat2 the returned value is 114.72.

And it should be 114.73

This is my difficulty.

Maybe I have not been very clear in my previous question.

There is another way to round values?

Thank you again!



Io non ho provato, ma... (I have not tried, but...)


Edit1.Text=NumberFormat2(Round2(MyResult+0.005,2), 0,2,2, False)

should work
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
This is what you need:
B4X:
dim MyResult as double  = 114.725 
msgbox(Round2(MyResult,2),"")   'displays 114.73
 
Upvote 0

Eugenio

Member
Licensed User
Longtime User
This is what you need:
B4X:
dim MyResult as double  = 114.725
msgbox(Round2(MyResult,2),"")   'displays 114.73

Mahares

It worked perfectly.

I would like to thank everyone who participated in any way in this post.

Thanks all.
 
Upvote 0
Top