NXT text and number displaying
Posted: 15 Jun 2011, 00:54
Often I use text and number display functions to debug programs. I also use them a lot for NXT -> human interface in stable programs. I have recently been doing more with floating point numbers, and have seen several things I don't care for.
Here is a scenario:
I have a thermometer that is precise to about 0.02 degrees. I want to display the number in floating point, but I don't want it to read "24.1284", I want it to drop x number of exponents, so it will display "24.1". What I have been doing is calculating the temperature in floating point, multiplying by 10, setting it to a int, then setting it back to a float, and dividing it by 10. Sure, this makes it display "24.1", but when it is 24.0, it displays "24", which isn't what I want. That ".0" is very significant, and I want it displayed.
What I need to do is convert the number into a string and then display it as text. NumToStr works fine, but it drops exponent 0's, or anything in or beyond the 10,000th's place.
How do I do this? I came up with a clumsy function that does basically what I want, but I want to know how to do it "properly".
Here is a scenario:
I have a thermometer that is precise to about 0.02 degrees. I want to display the number in floating point, but I don't want it to read "24.1284", I want it to drop x number of exponents, so it will display "24.1". What I have been doing is calculating the temperature in floating point, multiplying by 10, setting it to a int, then setting it back to a float, and dividing it by 10. Sure, this makes it display "24.1", but when it is 24.0, it displays "24", which isn't what I want. That ".0" is very significant, and I want it displayed.
What I need to do is convert the number into a string and then display it as text. NumToStr works fine, but it drops exponent 0's, or anything in or beyond the 10,000th's place.
How do I do this? I came up with a clumsy function that does basically what I want, but I want to know how to do it "properly".