The number in more than 3 decimal places ?

  • Thread starter Thread starter mbolhi
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around how to display numerical values with more than three decimal places in programming, specifically in the C language and BASIC. Participants seek guidance on the appropriate commands and data types to achieve this formatting.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant asks how to display a number with more than three decimal places, providing an example with a variable U.
  • Another participant suggests using the long float command in C, specifically the format specifier %12.10lf.
  • A participant expresses confusion about the usage of the command and requests clarification on the syntax.
  • Further clarification is provided with an example of the printf function in C, showing how to format the output.
  • One participant identifies themselves as a novice and requests additional resources or references for learning.
  • A suggestion is made to consult C programming books or specific online resources for further understanding of the 'lf' format specifier.
  • A later reply notes that the issue may stem from using a single or short float type variable and recommends using a double or long double type for better precision.

Areas of Agreement / Disagreement

Participants generally agree on the need to use appropriate data types and format specifiers to display numbers with more precision, but there is no consensus on the best resources or methods for beginners.

Contextual Notes

Some limitations include the assumption that participants have a basic understanding of programming concepts, and there may be unresolved questions about the specific implementation details in different programming environments.

Who May Find This Useful

This discussion may be useful for novice programmers seeking to understand numerical formatting in C and BASIC, as well as those looking for resources to improve their programming skills.

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 the 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.
 

Similar threads

Replies
25
Views
4K
Replies
9
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 53 ·
2
Replies
53
Views
4K
  • · Replies 17 ·
Replies
17
Views
3K
Replies
6
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
7K
Replies
3
Views
3K