Select to view content in your preferred language

Arcade question: Round() function

1105
2
Jump to solution
07-10-2022 04:47 PM
WingCheung1
Emerging Contributor

Hello,

I wrote a very simple expression and used the Round function. The output of the Round function  (i.e. 3.14) is correct, but when I multiply that output by a constant of 10, it is giving me the answer of 31.400000000000002 instead of 31.4. Is there a simple explanation for this? Did I miss something? Thanks!

 

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

It is called "floating point representation" an historic issue well covered.

you might want to round the multiplied value as well.

Python example, which you can emulate in arcade with concatenation

"{} vs {}".format(round(math.pi, 2), round(math.pi * 10, 1))
'3.14 vs 31.4'


... sort of retired...

View solution in original post

0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

It is called "floating point representation" an historic issue well covered.

you might want to round the multiplied value as well.

Python example, which you can emulate in arcade with concatenation

"{} vs {}".format(round(math.pi, 2), round(math.pi * 10, 1))
'3.14 vs 31.4'


... sort of retired...
0 Kudos
WingCheung1
Emerging Contributor

Thank you for the quick reply, Dan! 

0 Kudos