Double data types

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Double data types

Jump to solution
624 Views
Bay
Contributor III

How to display the float number with 9 decimal places. example: 0.123456789

I have tried with below code, but the terminal displays The number is lf.

double number1=0.123456789;

PRINTF("The number is %lf", number1);

0 Kudos
Reply
1 Solution
598 Views
Alice_Yang
NXP TechSupport
NXP TechSupport
0 Kudos
Reply
3 Replies
591 Views
frank_m
Senior Contributor III

As Alice_Yang suggested, just specifiy the precision in the format string.
If you don't, the default value (usually 6 digits) is used.

> Double data types

> How to display the float number with 9 decimal places. example: ...

I hope you realized that "double" and "float" are different types of different size.
Only "float" is natively supported by Cortex M FPUs, and several clib implementations (i.e. printf()/scanf()) have no or limited support for "double" either.
Check the respective library documentation.

0 Kudos
Reply
599 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @Bay 

 

How about PRINTF("The number is %.9f", number1);.

https://community.nxp.com/t5/LPC-Microcontrollers/LPC54628-Printf-Floating-numbers-doesnt-have-minus...  

 

BR

Alice

0 Kudos
Reply
590 Views
Bay
Contributor III
Hi Alice,
Thanks. It works.
How about if the user enters unknown number of decimal places?
How should write in this code line?
SCANF("%f ",&number1);
Why is the double data type not using %lf?
0 Kudos
Reply