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 Professional Discussion / have a problem with variable#

Author
Message
Brux
13
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 27th May 2015 15:58

I made a program for managing current account
but what I want to print the variable myvar # = 45.10
on the screen it appears to me 45.0999984741
how must I do to print only the first two decimal places?
thanks
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th May 2015 17:08
This snippet might help.





Powered by Free Banners
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 27th May 2015 18:20
if you need your variable to remain a numeric value for any reason try this:

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th May 2015 01:27
How would that help? Try this:



The strange value is almost certainly a result of trying to convert a decimal float to a binary one.



Powered by Free Banners
Brux
13
Years of Service
User Offline
Joined: 12th Oct 2011
Location:
Posted: 29th May 2015 19:51


I managed !!

myvar#=45.10
myvar#=myvar#*100
Sum$=str$(myvar#): L=Len(sum$)
Sum$=left$(Sum$,L-2) + "." + right$(Sum$,2)
print sum$

display 45.10

Thank's at all
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th May 2015 20:55
Well done.

Interesting that it works though.



Powered by Free Banners

Login to post a reply

Server time is: 2025-08-09 02:29:39
Your offset time is: 2025-08-09 02:29:39