Double data types

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
1,553件の閲覧回数
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 件の賞賛
返信
1 解決策
1,527件の閲覧回数
Alice_Yang
NXP TechSupport
NXP TechSupport
0 件の賞賛
返信
3 返答(返信)
1,520件の閲覧回数
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 件の賞賛
返信
1,528件の閲覧回数
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 件の賞賛
返信
1,519件の閲覧回数
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 件の賞賛
返信