Reading the number in the decimal place
BlitzMax Forums/BlitzMax Beginners Area/Reading the number in the decimal place
| ||
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 |
| ||
Local a:Double = 105942864401708.62:Double Local b:Int = a*100 - Long(a)*100 Print b |
| ||
Never mind. I just realised I could go via string variables. Solved. :) |
| ||
Oh. Thanks Jesse. I'll try that too. Thanks. |
| ||
Hi, Just to note that decimal point differs in different localizations so with strings both '.' and ',' are possible. -Henri |
| ||
Or you can use mod: |
| ||
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. |
| ||
Here's the simplest and quickest way:Local number:Float = 1.25 Print (number - Int(number)) |