Floats and Decimals 2

BlitzMax Forums/BlitzMax Programming/Floats and Decimals 2

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

The reason Blitzmax probably doesn't round floats when printing, is because if it did then you couldn't print the real float value.

Hm.. I tried to make a round function or you, and it might work in Blitzmax, (assuming int rounds up/down... if not maybe there is a round commands in bmax) but it seems to work oddly in Blitzplus.

 x#=13.12345 
Print x#
Print Round#(X#, 1)
Print Round#(X#, 4)
Print (X# * 10.0^4)
Print Int(X# * 10.0^4)

WaitKey()

Function Round#(N#, DecimalPlaces)
	Return Int(N# * 10.0^DecimalPlaces) / 10.0^DecimalPlaces
End Function



The odd thing is the last two print statements.

The first one returns 131235.0 The second one returns 131234.

Here's why it's odd:

We start with:
13.12345

We multiply by 10^4 ... 10,000

Which should give us:
131234.5

So far so good. Now when we print X#, we get:
131235.0

Okay... that appears to be rounded up from 131234.5... Maybe that is intentional. No problem.

But wait!

If X# equals 131234.5, and print rounds it up, and int() is supposed to round floats up too, then why do we get:
131234

When we print int(x#) instead of x#?

I understand if Blitz rounds up when it prints values... But if INT is also supposed to round up, then why doesn't the value match the one printed without int, and presumably also rounded up?