How to round off a float value in Firemonkey Mobile Delphi XE6?

2

I'm doing a mobile application for android requests in Delphi XE6, in this application I make a discount calculation, which divides the amount of Discount given by 100 minus the total value, but the value of the price is already coming brittle from the base of customer data ex: 11,568.

I wanted to know how do I round this value?!?!; I found examples using 'round' but it rounds off the values.

    
asked by anonymous 26.01.2015 / 17:46

2 answers

4

Never ever never ever never ever use a float to handle monetary values.

They do not accurately store values that are expected of money, it is well expected that after some calculations sum a penny or two. The correct thing is to store the total number of cents as an integer. Thus, R $ 5.00 will become 500 and R $ 19.90 will become 1990 . Keeping these values always as integers, over any calculation you make, will not require rounding or precision problems.

    
26.01.2015 / 17:54
2

Round supports two parameters. The second is the number of decimal places you want in the result.

For example, if you do:

Round(11.568, 2);

You will get 11.57 (or 11.57 when on display in Brazilian culture).

The ideal type to work with monetary values in Delphi, however, is Currency .

    
26.01.2015 / 17:58