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 / Information about Float variables

Author
Message
davidhan
10
Years of Service
User Offline
Joined: 17th Oct 2014
Location:
Posted: 20th Oct 2014 06:09
This is rather embarrasing since I have been using DBPro for years.
But during the last year I have worked more with MEL and C# etc, so I may have forgotten how to do it (tough I have searched, and looked through my old codes)

The problem is I cant seem to get float variables to work

like:

var# = 640/100
print var#
wait key

The result I get is 6

It should be 6,4

So something is wrong.

Does anyone know what could be wrong?

A Nice day.
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 20th Oct 2014 13:35
It's just the way DBPro works - if your equation multiplies or divides by a whole number, the result is a whole number.

You need to specify the decimal, like:

var#=640.0/100.0

I am the one who knocks...
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 21st Oct 2014 11:15
The resulting data type of an operation is cast based on the two input data types. If both sides of the operator are integer, then the operation will be performed as an integer operation. But, If either the left or right hand side is a float, the operation will be performed on the FPU as float.

Login to post a reply

Server time is: 2025-05-14 10:46:03
Your offset time is: 2025-05-14 10:46:03