Float Rounding Problem

Discuss PC Developer and Web Developer projects and features here.
Post Reply
wayne_millard
Posts: 94
http://meble-kuchenne.info.pl
Joined: Fri Dec 04, 2020 6:12 pm
Has thanked: 1 time
Been thanked: 9 times

Float Rounding Problem

Post by wayne_millard »

Hi Matrix Team,

Im having some problems with Float Rounding. I have attached an example file.
What am i doing wrong? Only one of the roundings seem to do something.

Thanks,

Wayne M
Float Rounding.fcsx
Float Rounded Problem
(8.34 KiB) Downloaded 114 times

BenR
Matrix Staff
Posts: 1726
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 438 times
Been thanked: 602 times

Re: Float Rounding Problem

Post by BenR »

Hello Wayne,

It looks like it's working in the simulation, but maybe the precision of storing and displaying the number is not ideal. I beleive this is the limitation of the float format rather than anything else.
Rounding.jpg
Rounding.jpg (18.33 KiB) Viewed 1854 times
This is a nice tool as it allows you to enter a real number and it will show you the floating point representation of the number.

https://www.h-schmidt.net/FloatConverter/IEEE754.html

100.7 is actually stored as 100.6999969482421875
100.68 as 100.68000030517578125
etc

wayne_millard
Posts: 94
Joined: Fri Dec 04, 2020 6:12 pm
Has thanked: 1 time
Been thanked: 9 times

Re: Float Rounding Problem

Post by wayne_millard »

Hi everyone

What I wanted was to only display to two places after the decimal point.

I thought in the past when you did a round to two decimal places you would loose all the other numbers.

So how do you do it.

Thanks
Wayne m

mnfisher
Valued Contributor
Posts: 953
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 507 times

Re: Float Rounding Problem

Post by mnfisher »

Hi Wayne,

Try using str = FloatToStr$(val, 2)
Then display the string str.

Martin

wayne_millard
Posts: 94
Joined: Fri Dec 04, 2020 6:12 pm
Has thanked: 1 time
Been thanked: 9 times

Re: Float Rounding Problem

Post by wayne_millard »

Martin, Thanks I forgot about that.

Wayne

Post Reply