The number in more than 3 decimal places ?

  • Thread starter Thread starter mbolhi
  • Start date Start date
AI Thread Summary
To display a number with more than three decimal places in C, the correct approach involves using the `printf` function with a specific format specifier. The format `%12.10lf` is recommended, where `lf` indicates a long float. This allows for greater precision in the output. It's important to ensure that the variable is defined as a double or long double to prevent truncation of the value. For beginners, consulting a C programming book or online resources can provide foundational knowledge on using these commands effectively.
mbolhi
Messages
10
Reaction score
0
hello,

How could I make my answer display the number in more than 3 decimal places?

for example

Variable U = 0.026283623901941

instead of

U = 0.02628

which command to use?

thanks for ur help!
 
Technology news on Phys.org
Hi,
in C language you can use longfloat command..
E.g., try %12.10lf command and see the result..
 
thnaks but am a bit confused as to how to use this command ?

lf in front of the number?

show me teh xyntax please.

thanks
 
printf ("\n something : %12.10lf",another);
do you know some basics of programming using C?
 
Last edited:
thansk, well I am quite novice

any reference or link would be much appreciated

thanks for ur help ;)
 
Hi,
well, please look into any C-programming book..just first few pages or 1st chapter..you will find 'lf' explained..
you can also see 'let us c' by y. ganetkar.
or http://www.cs.cf.ac.uk/Dave/C/CE.html
cheers
 
mbolhi said:
hello,

How could I make my answer display the number in more than 3 decimal places?

for example

Variable U = 0.026283623901941

instead of

U = 0.02628

which command to use?

thanks for ur help!

It looks like your using a single (BASIC) or a short float (C) type variable.

As others have mentioned use a double (BASIC) or a double (C) or long double when defining the variable. Also as others have mentioned make sure the print instruction converts the variable to the right format (double or long double) so that you don't get the truncation that is occurring.
 
Back
Top