Rounding a Float

Any bugs you encounter with Flowcode should be discussed here.
Post Reply
MJU20
Posts: 364
http://meble-kuchenne.info.pl
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 105 times
Been thanked: 74 times

Rounding a Float

Post by MJU20 »

In this topic: https://www.flowcode.co.uk/mmforums/view ... 794#p95329 someone asked how to round a Float to a certain amount of decimals.

This isn't fixed yet?
If I round a float to 1 decimal and then convert it to a string, I still get 6 decimals.

medelec35
Valued Contributor
Posts: 2255
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 695 times
Been thanked: 767 times

Re: Rounding a Float

Post by medelec35 »

The easiest way to round to one decimal place for example is

Code: Select all

StringVar = FloatToString$ (FloatVar,1)
It will also round up to the nearest decimal place.
I'm sure that works well.
Martin

Steve-Matrix
Matrix Staff
Posts: 1769
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 258 times
Been thanked: 413 times

Re: Rounding a Float

Post by Steve-Matrix »

It is also relatively easy to work around by first multiplying (or dividing) by 1000 (or whatever factor you want), then rounding to the nearest integer, and then dividing (or multiplying) by the same factor.

Post Reply