1
votes

I've been working on the project and just found this. Basically if I multiple the integer value by the some kind of decimal(float) the value I receive is not exact. For example <%= 800 * 1.1 %> in the html, returns 880.0000000000001 instead of just 880.

Any possible explanations to why it happens? And is it possible to round the number?

Edit: <%= 800 + (800 * 0.1) %> works fine

Using the reply below, I've modified code to <%= Float.round(value, 2) %>, so the value gets rounded to two decimal places

1
"Any possible explanations to why it happens?" - What Every Computer Scientist Should Know About Floating-Point Arithmetic.CodeCaster

1 Answers

4
votes

To round a float use, round()

<%= 800 * 1.1 |> round %>