I believe you are using a 4 digit display with a decimal point possibly displayed the right of each digit. Also, you’re using a library called SevSeg (your code includes Sevseg.h).
You are trying to automatically set the second parameter in this call:
sevseg.setNumber() – This function prints the number to the display. For example,
sevseg.setNumber(4) will print the number “4” to the display. You can also print numbers with decimal points. For example, to print the number “4.999”, you would use
sevseg.setNumber(4999, 3) . The second parameter (the 3) defines where the decimal point is located. In this case it’s 3 digits from the right most digit. On a single digit display, setting the second parameter to “0” turns on the decimal point, while setting it to “1” turns it off.
If this is all correct, you just need to determine where and if you want the decimal point.
For numbers less than 10, you can display up to 3 digits to the right of the decimal point. otherwise
For numbers less than 100, you can display up to 2 digits to the right of the decimal point. otherwise
For numbers less than 1000, you can display up to 1 digit to the right of the decimal point. otherwise
You can display a number only as high as 9999 (0 digits to the right of the decimal point)
From your examples it appears you are not displaying only integers.
You wish to have as many digits to the right of the decimal point as possible.
So far, is this all correct?
I think you will have an easier and better display if you do not have variable precision within a range. Thus if your numbers are less than 100 but not less than 10, you always display them as xx.xx , for example 37.51 and 10.50. You would not display those numbers as 37.51 and 10.5
That’s not a bad thing to do since it keeps the precision of the numbers in each of the displayable ranges constant rather than jumping around, which people might find confusing. Think dollars and cents. 7.49, 7.50, 7.51 is better than 7.49, 7.5, 7.51
I took a shot in the dark as to what you are asking. Did I get it right?
If I did, then all your code has to do is first figure which range to use for a number, calculate the needed number of digits to the right of the decimal point, and then make a call with to setNumber with two integers as arguments. The first argument, say for a number “ab.cd” is calculated as the integer ab * 100 + cd. The second argument would be 2.
As long as I’m shooting in the dark,
I think you may be in a country where the decimal point is displayed as a comma and possibly the separator between groups in numbers with many digits is an empty space or a period. Very confusing. See this article:
( http://www.languageediting.com/format-numbers-eu-vs-us/ )