Reading the number in the decimal place

BlitzMax Forums/BlitzMax Beginners Area/Reading the number in the decimal place

CandlestoneDave(Posted 2015) [#1]
Hi All

I'm sure this is simple, but I can't figure it out for the life of me.

I have a variable (a double) which contains a value such as:

105942864401708.62

What I want to do is simply transfer the digits in the decimal places (ie: 62) to an integer.

If anyone has any ideas, it would be greatly appreciated.

Thanks

Dave


Jesse(Posted 2015) [#2]
Local a:Double = 105942864401708.62:Double
Local b:Int = a*100 - Long(a)*100
Print b



CandlestoneDave(Posted 2015) [#3]
Never mind. I just realised I could go via string variables. Solved. :)


CandlestoneDave(Posted 2015) [#4]
Oh. Thanks Jesse. I'll try that too. Thanks.


Henri(Posted 2015) [#5]
Hi,

Just to note that decimal point differs in different localizations so with strings both '.' and ',' are possible.

-Henri


Scaremonger(Posted 2015) [#6]
Or you can use mod:



Matty(Posted 2015) [#7]
Not sure what the purpose is but if you are doing hundreds or thousands of these operations per frame then it is worth keeping in mind that typically string ops are much much slower than basic mathematical ops.


AdamStrange(Posted 2015) [#8]
Here's the simplest and quickest way:

Local number:Float = 1.25
Print (number - Int(number))