How do I print a 12 digit number

Forum for posting topics and questions about anything.
Post Reply
RetroBoy
Posts: 21
Joined: Sat Feb 26, 2022 11:29 am
Location: U.K.

How do I print a 12 digit number

Post by RetroBoy » Tue Apr 26, 2022 9:49 am

HELP.
I am trying to print a 12 digit number or 3decimal9 or 4decimal9, to a 2004 LCD. I have tried various ways however I always end up with SmartLCDI2C displaying totally stupid values owing to the fact it either requires ' int ' or ' string ' values.
What I have are a variety of 'LONG/LONG LONG' or 'FLOAT/DOUBLE' values.
Any help would be extreemely welcome.

andrew
Site Admin
Posts: 1240
Joined: Sun Aug 05, 2012 4:15 pm

Re: How do I print a 12 digit number

Post by andrew » Tue Apr 26, 2022 2:41 pm

I have tried various ways however I always end up with SmartLCDI2C displaying totally stupid values owing to the fact it either requires ' int ' or ' string ' values

The library has now been updated to version 0.3 (download/file.php?id=797). In this new version the print function now supports floating point numbers. You can simply print a float like this:


  1. float value = 1234.56;
  2. SmartLCD.Print(value, 2);

Note that the second parameter in the print function is optional and specifies the number of decimal places to print the number to. However....

I am trying to print a 12 digit number or 3decimal9 or 4decimal9, to a 2004 LCD.
What I have are a variety of 'LONG/LONG LONG' or 'FLOAT/DOUBLE' values.
If you're using a standard 8 bit Arduino (Uno, Nano, Leonardo, etc) I'm afraid handling numbers of that size is going to be a problem as long is 9 to 10 digits, floats have only 6 to 7 digits of precision, and doubles are the same size as a float.


Quote from Arduino.cc:

Floats have only 6-7 decimal digits of precision. That means the total number of digits, not the number to the right of the decimal point. Unlike other platforms, where you can get more precision by using a double (e.g. up to 15 digits), on the Arduino, double is the same size as float.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

RetroBoy
Posts: 21
Joined: Sat Feb 26, 2022 11:29 am
Location: U.K.

Re: How do I print a 12 digit number

Post by RetroBoy » Tue Apr 26, 2022 6:09 pm

Hi Andrew.
Thanks for the very quick responce. I will be honest and say the reason for my 'Original' post is because I am trying to print extra GPS data. I would expect you to know all the following, so please do not take offence at this responce.

i ) LAT/LNG are normally extressed at 3decimal6. However the ACTUAL received data comes in BILLIONTHS of a degree. I suppose it depends on how accurate I want to display LAT/LNG data. ( I want exact meaning 123.0123456789. If I then multiply the 'decimal' by 1000000000 I get LONG NUMBERS, sometimes, as you have said, even 'double and float' give me the wrong answers.!?!?!?)
ii ) When doing the maths ' MOD (%)' takes tooo longgg. SO I am stripping all the maths down to the simple 4 functions of
( + - * / ), this can give me very long numbers as I am sure you can imagine., but the speed increase is massive.

So to end, I, and many others, am very gratefull for the change you have made. ( I will have to re-think what data I want/need to display on the 3rd LCD ).

RetroBoy
Posts: 21
Joined: Sat Feb 26, 2022 11:29 am
Location: U.K.

Re: How do I print a 12 digit number

Post by RetroBoy » Tue Apr 26, 2022 7:18 pm

Hi Andrew,
Uploaded new SmartLCD file, getting constant errors.

Arduino: 1.0.6 (Windows XP), Board: "Arduino Nano w/ ATmega328"
C:\Program Files\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:\Program Files\Arduino\hardware\arduino\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\variants\eightanaloginputs -IC:\Program Files\Arduino\libraries\Wire -IC:\Program Files\Arduino\libraries\SoftwareSerial -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\TinyGPSPlus-1.0.3\src -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\RTClib -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\SmartLCD -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\HCBMP180 -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\mLink C:\DOCUME~1\Pc-User\LOCALS~1\Temp\build6592942028091563212.tmp\GPS2RTC_NEW.cpp -o C:\DOCUME~1\Pc-User\LOCALS~1\Temp\build6592942028091563212.tmp\GPS2RTC_NEW.cpp.o

C:\Program Files\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:\Program Files\Arduino\hardware\arduino\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\variants\eightanaloginputs -IC:\Program Files\Arduino\libraries\Wire -IC:\Program Files\Arduino\libraries\SoftwareSerial -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\TinyGPSPlus-1.0.3\src -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\RTClib -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\SmartLCD -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\HCBMP180 -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\mLink -IC:\Program Files\Arduino\libraries\Wire\utility C:\Program Files\Arduino\libraries\Wire\Wire.cpp -o C:\DOCUME~1\Pc-User\LOCALS~1\Temp\build6592942028091563212.tmp\Wire\Wire.cpp.o

C:\Program Files\Arduino\hardware\tools\avr\bin\avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:\Program Files\Arduino\hardware\arduino\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\variants\eightanaloginputs -IC:\Program Files\Arduino\libraries\Wire -IC:\Program Files\Arduino\libraries\SoftwareSerial -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\TinyGPSPlus-1.0.3\src -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\RTClib -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\SmartLCD -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\HCBMP180 -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\mLink -IC:\Program Files\Arduino\libraries\Wire\utility C:\Program Files\Arduino\libraries\Wire\utility\twi.c -o C:\DOCUME~1\Pc-User\LOCALS~1\Temp\build6592942028091563212.tmp\Wire\utility\twi.c.o

C:\Program Files\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:\Program Files\Arduino\hardware\arduino\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\variants\eightanaloginputs -IC:\Program Files\Arduino\libraries\Wire -IC:\Program Files\Arduino\libraries\SoftwareSerial -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\TinyGPSPlus-1.0.3\src -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\RTClib -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\SmartLCD -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\HCBMP180 -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\mLink -IC:\Program Files\Arduino\libraries\SoftwareSerial\utility C:\Program Files\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp -o C:\DOCUME~1\Pc-User\LOCALS~1\Temp\build6592942028091563212.tmp\SoftwareSerial\SoftwareSerial.cpp.o

C:\Program Files\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp:59: warning: only initialized variables can be placed into program memory area
C:\Program Files\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:\Program Files\Arduino\hardware\arduino\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\variants\eightanaloginputs -IC:\Program Files\Arduino\libraries\Wire -IC:\Program Files\Arduino\libraries\SoftwareSerial -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\TinyGPSPlus-1.0.3\src -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\RTClib -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\SmartLCD -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\HCBMP180 -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\mLink -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\TinyGPSPlus-1.0.3\src C:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\TinyGPSPlus-1.0.3\src\TinyGPS++.cpp -o C:\DOCUME~1\Pc-User\LOCALS~1\Temp\build6592942028091563212.tmp\TinyGPSPlus-1.0.3\TinyGPS++.cpp.o

C:\Program Files\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:\Program Files\Arduino\hardware\arduino\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\variants\eightanaloginputs -IC:\Program Files\Arduino\libraries\Wire -IC:\Program Files\Arduino\libraries\SoftwareSerial -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\TinyGPSPlus-1.0.3\src -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\RTClib -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\SmartLCD -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\HCBMP180 -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\mLink -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\RTClib\utility C:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\RTClib\RTClib.cpp -o C:\DOCUME~1\Pc-User\LOCALS~1\Temp\build6592942028091563212.tmp\RTClib\RTClib.cpp.o

C:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\RTClib\RTClib.cpp:58: warning: only initialized variables can be placed into program memory area
C:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\RTClib\RTClib.cpp: In constructor 'DateTime::DateTime(uint32_t)':
C:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\RTClib\RTClib.cpp:92: warning: comparison between signed and unsigned integer expressions
C:\Program Files\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:\Program Files\Arduino\hardware\arduino\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\variants\eightanaloginputs -IC:\Program Files\Arduino\libraries\Wire -IC:\Program Files\Arduino\libraries\SoftwareSerial -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\TinyGPSPlus-1.0.3\src -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\RTClib -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\SmartLCD -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\HCBMP180 -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\mLink -IC:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\SmartLCD\utility C:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\SmartLCD\SmartLCDI2C.cpp -o C:\DOCUME~1\Pc-User\LOCALS~1\Temp\build6592942028091563212.tmp\SmartLCD\SmartLCDI2C.cpp.o

C:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\SmartLCD\SmartLCDI2C.cpp:131: error: default argument given for parameter 2 of 'void SmartLCD::Print(float, uint8_t)'
C:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\SmartLCD\/SmartLCDI2C.h:93: error: after previous specification in 'void SmartLCD::Print(float, uint8_t)'

Have tried with various decimal values, but always the same error. Is the update able to print negative double/float values ? My GPS data says my LNG is -X.xxxxxxxxxxxxxxx ( OK, I have asked for 9 digits ) ?

RetroBoy
Posts: 21
Joined: Sat Feb 26, 2022 11:29 am
Location: U.K.

Re: How do I print a 12 digit number

Post by RetroBoy » Tue Apr 26, 2022 9:21 pm

Hi Andrew.

Problems solved :

i) Negative Numbers need to be positive, ( or should I say when I tried a negative it failed; but simple to convert ).

ii) With the errors I was getting I took the libery of looking at SmartLCD.h & .cpp.

In .cpp there is a line that reads :

void SmartLCD::Print(float val, uint8_t dp = 0)

I changed the line to read :

void SmartLCD::Print(float val, uint8_t dp) i.e. Deleted the " = 0 "

Compiled OK, Loaded OK, Displays OK - even to 10decimal.

Hope my change will not affect the work you have done.

As an aside when I looked for function to do the work, nowhere brought up " dtostrf " as a work-around. The nearest I got was " ltostrf ". Anyway all sorted and many thanks.

Is it possible for me to be able to "PM" ?

andrew
Site Admin
Posts: 1240
Joined: Sun Aug 05, 2012 4:15 pm

Re: How do I print a 12 digit number

Post by andrew » Wed Apr 27, 2022 2:31 pm

C:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\SmartLCD\SmartLCDI2C.cpp:131: error: default argument given for parameter 2 of 'void SmartLCD::Print(float, uint8_t)'
C:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\SmartLCD\/SmartLCDI2C.h:93: error: after previous specification in 'void SmartLCD::Print(float, uint8_t)'
From the above two error messages it looks like the .cpp file got updated to 0.3 but the .h file didn't? You can check this as both files have the version number at the top.

The dp = 0 part specifies a default value if the dp parameter is left out of the print statement, I.e. if the number of decimal places isn't specified then it will print the number as an integer.


i) Negative Numbers need to be positive, ( or should I say when I tried a negative it failed; but simple to convert ).
I've check it and seems to be handling negative numbers fine for me? The following test sketch worked for me (with V0.3):

  1. #include "SmartLCDI2C.h"      
  2.  
  3. #define I2C_ADD 0x27          
  4.  
  5. SmartLCD SmartLCD(I2C_ADD);  
  6.  
  7.  
  8. void setup()
  9. {
  10.   SmartLCD.init();    
  11. }
  12.  
  13.  
  14.  
  15. void loop()                
  16. {
  17.   float value = -123.01234;
  18.  
  19.   SmartLCD.Print(value, 5);
  20.  
  21.   while(1);
  22. }

Is it possible for me to be able to "PM" ?
PMs are disabled on this forum as they can be used by bots to directly spam users. If there is anything you wish to privately discuss you can email support [at] hobbycomponents.com and it will get to me.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

RetroBoy
Posts: 21
Joined: Sat Feb 26, 2022 11:29 am
Location: U.K.

Re: How do I print a 12 digit number

Post by RetroBoy » Wed Apr 27, 2022 6:15 pm

Hi Andrew,

Again thank you for the quick responce ... however;

I have checked ' .cpp ' & ' .h ' both say ' 0.3 ', so I am very confused. Even your simple sketch gives the same error.
This report would have more information with
"Show verbose output during compilation" enabled in File > Preferences.
Arduino: 1.0.6 (Windows XP), Board: "Arduino Nano w/ ATmega328"
C:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\SmartLCD\SmartLCDI2C.cpp:131: error: default argument given for parameter 2 of 'void SmartLCD::Print(float, uint8_t)'
C:\Documents and Settings\Pc-User\My Documents\Arduino\libraries\libraries\SmartLCD\/SmartLCDI2C.h:93: error: after previous specification in 'void SmartLCD::Print(float, uint8_t)'
Just to make life even more stupid ( for me anyway ) I even have to include a ' , 0 ' at the end of ' now.year()' ie 'now.year(),0'.

The only way I can get it to work is without the ' = 0 '; could this be anything to do with me using v1.0.6 of IDE ? I only ask as I always have to include "Wire.h" to any sketch ( even your test of -123.01234 ).

andrew
Site Admin
Posts: 1240
Joined: Sun Aug 05, 2012 4:15 pm

Re: How do I print a 12 digit number

Post by andrew » Thu Apr 28, 2022 9:14 am

Yeah that's because now the default option DP = 0 has been removed from the library you're now having to specify the number of decimal places even though you don't need any. It looks like the library is seeing the output from 'now.year()' as a float and therefore using the floating point version of the function. One other workaround is you could try is to force it to use the int version by casting the output from the 'now.year()' to an int like this:

Code: Select all

SmartLCD.Print((int)now.year());

The only way I can get it to work is without the ' = 0 '; could this be anything to do with me using v1.0.6 of IDE ?

It's possible, V1.0.6 is a very old version of the IDE. That said though, I'd be more inclined to suspect that you may still have an old copy of the library somewhere that the IDE can still see.

As it all seems to work for me, and if you're happy with your workarounds, I'm happy to leave the current V0.3 as is. However, if you want to investigate further I would suggest checking your \Documents\Arduino\libraries folder for any other copies of the .h (and .cpp) files. Note that it's not enough just to put old copies in a sub folder or a renamed folder within the libraries folder, any old version must be completely removed from the Arduinos libraries folder otherwise the IDE may still see it and use it instead of the correct one.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Post Reply

Return to “General Discussion”