Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Float to string?

Author
Message
Tomalla
18
Years of Service
User Offline
Joined: 2nd May 2008
Location:
Posted: 2nd May 2008 19:42
Well, I have to convert float ( real ) value, to string one. I used STR$ function, buta ... it rounds it by the way!

For example: 167.36875 -> 167.37

What I have to do, to convert WHOLE float value to string? ( huh, of course not when value is infinite, i.e. sqrt(2))

I guess it IS possible, but don't know what have to do
TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 2nd May 2008 20:32 Edited at: 2nd May 2008 20:38
Quote: "it rounds it by the way!"


Yes - all computers do and there's no escaping it.

The value is rounded to 167.369 at the moment you put 167.36875 into a float variable so STR$() is working correctly.

The only thing you can do is simulate floats yourself using integers.

Have a read of this thread as it also covers float precision (it's for DBPro but the theory is relevant to DBC too):

http://forum.thegamecreators.com/?m=forum_view&t=127049&b=7

TDK_Man

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 5th May 2008 05:12
I'm going to try that sounds geeky fun...

It is far better to complete a 10 line program than to start a 10,000 line program.

Login to post a reply

Server time is: 2026-07-06 00:09:57
Your offset time is: 2026-07-06 00:09:57