How do you keep the digits to right of decimal?
BlitzMax Forums/BlitzMax Programming/How do you keep the digits to right of decimal?
| ||
I need percision. Actually more like 3 digits to the right of the decimal. 1024/329 comes out to 2.334 on a calculator. |
| ||
num - int(num) ? |
| ||
Do you mean using floats/doubles or something else? <edit> BTW : Is your calculator broken? |
| ||
No, the calculator is not broken :) It seems I can't use floats/doubles because they round 2.334 to 2.0. Is there another way? A mod perhaps. |
| ||
MM, You're passing float point values to integers at some point? Be sure to be using superstrict in your code.Local a:Int = 10 Local B:Float = 0.454345 Local c:Float C = A + B A = A + B Print "A has a value of " + A Print "C has a value of " + C If you don't set the data type of a variable, it is an integer. Using SuperStrict helps a lot in this situations. |
| ||
Big non-floatingpoint numbers, and place a floatingpoint dot yourself in a string.. |
| ||
Print 1024.0/329.0 results in 3.11246204. P.S. ... 1024/329 comes out to 2.334 on a calculator. does it *really*? |
| ||
this code may be helpful for formatting floats in blitz |
| ||
If you want your number to be precicely accurate to 3 decimal places, multiple an integer by 1000 before you do your divide, then divide it by 1000 when you want to use it, but either way the float isn't going to be able to represent it accurately. |
| ||
<edit> BTW : Is your calculator broken? Print 1024.0/329.0 results in 3.11246204. P.S. ... 1024/329 comes out to 2.334 on a calculator. does it *really*? Oops. I meant 768/329 = 2.334 Calculator was not broken, just my brain for the moment:) What I need is to get the quotient of 768/329 during runtime. I'm trying to scale images by dividing the GraphicsHeight divided by the ImageHeight, and GraphicsWidth divided by the ImageWidth. My pictures are all different resolutions; so I need to scale them based on the Graphic mode that is chosen. I don't care about if they look funny right now. |
| ||
MM, You're passing float point values to integers at some point? Be sure to be using superstrict in your code. Ziggy, you are correct. The problem is that i needed to do my division like this: iscaleY = 768.0 / 329.0 what I was doing is this: iscaleY = 768 / 329 |