Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simpletext doesn't display correctly with certain character counts #56

Open
AndyLindsay opened this issue Dec 12, 2016 · 0 comments
Open

Comments

@AndyLindsay
Copy link
Contributor

AndyLindsay commented Dec 12, 2016

From: http://forums.parallax.com/discussion/165609

(Thanks jcook!)

The simpletext print function seems to have problems when printing floating point numbers.

I discovered this when converting a temperature measured with the DS18B20 temperature sensor to Fahrenheit. The sensor outputs the temperature in units of 1/16 degree Celsius and I am displaying the temperature in Fahrenheit with a precision of 0.1°. When the sensor returns a value of 0xff3c (-12.25°C) I expect the displayed value to be either 9.9 or 10.0 since the actual temperature is 9.95°F. Instead my display shows 0.0°F. I experimented with printing the conversion result with different number of digits after the decimal point.

When using the default number of digits the output is okay:
print("%f\n", 32+(9*(-196))/80.0);
results in displaying: 9.950001

When using one digit after the decimal point the problem is evident:
print("%.1f\n", 32+(9*(-196))/80.0);
results in displaying: 0.0

When using two digits after the decimal point the output is okay:
print("%.2f\n", 32+(9*(-196))/80.0);
results in displaying: 9.95

I looked at the source code for the simpletext library and I think the issue is in the float2string function. It has some code to determine the number of digits to print that isn't working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant