Main Menu

How to format my decimal variable?

Started by xboxisfinished, 21 May, 2015, 09:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

xboxisfinished

I have set a timer with # float on it. When the timer goes down in decimal point -0.01 it goes down fine

2.00, 1.99, 1.98, 1.97, etc...respectively! Sweet! Problem I have when it reaches 0.98, decimal then it adds 0.980000000 on it
how do I fix it so it contain the format

#0.00 only?

Thanks in advance.

SamuraiCrow

Fixed point is easier to work with than floating point.  Just make an integer variable that is 100 times greater and then print n/100;".";n mod 100

If you must use floating point, you'll have to use string manipulation to avoid the rounding error.

xboxisfinished

Quote from: SamuraiCrow on 23 May, 2015, 04:03 PM
Fixed point is easier to work with than floating point.  Just make an integer variable that is 100 times greater and then print n/100;".";n mod 100

If you must use floating point, you'll have to use string manipulation to avoid the rounding error.

Assuming I want to use the string manipulation. Can you give me an example of how to do that? Like a format string manipulation?

Thanks in advance.

Sidewinder

If you are using the Print instruction to do this output you can add a Using directive to it and specify the exact format of the output:

Print Using "#.##";TIMER#

This should limit the output to 1 digit before the decimal point and two digits after.
- Sidewinder

xboxisfinished

Quote from: Sidewinder on 24 May, 2015, 06:03 PM
If you are using the Print instruction to do this output you can add a Using directive to it and specify the exact format of the output:

Print Using "#.##";TIMER#

This should limit the output to 1 digit before the decimal point and two digits after.

Thank you so much! :)

SamuraiCrow

Huh.  I looked into the online manual for print using and could not find it.

xboxisfinished

Quote from: SamuraiCrow on 26 May, 2015, 07:04 PM
Huh.  I looked into the online manual for print using and could not find it.

It is there! It works!! Weeeee!!!

Sidewinder

Yeah, it took me some time to find it too.  It's under "Using" in the index, section 5.6.13.
- Sidewinder