outputing text

  • Follow


Hi,
I want to print most significant digit of a number

eg. if its 1.234455666, I want to print 1.23445
if it is 123.123456, I want to print 123.123

I tried using printf("%6f",value); but  it means placing 6 digit of
decimal value.

I want to have total of 6 digits only.
how do I do this?

Thanks
0
Reply a.k.vora (41) 9/26/2008 10:32:04 PM

Neel wrote:
> Hi,
> I want to print most significant digit of a number
> 
> eg. if its 1.234455666, I want to print 1.23445
> if it is 123.123456, I want to print 123.123
> 
> I tried using printf("%6f",value); but  it means placing 6 digit of
> decimal value.
> 
> I want to have total of 6 digits only.
> how do I do this?
> 
> Thanks

You want to do printf("%6g",value);

g is for double in scientific format (ie number of sig figs)
0
Reply mistere8416 (9) 9/26/2008 10:54:49 PM


> 
> You want to do printf("%6g",value);
> 
> g is for double in scientific format (ie number of sig figs)

You might also want to look at this:
http://www.thinkage.ca/english/gcos/expl/nsc/lib/printf.html

I didn't know there were so many possibilities that were actually ANSI, 
wonder what C99 etc says about this
0
Reply mistere8416 (9) 9/27/2008 3:06:07 AM

MisterE wrote:
> 
>>
>> You want to do printf("%6g",value);
>>
>> g is for double in scientific format (ie number of sig figs)
> 
> You might also want to look at this:
> http://www.thinkage.ca/english/gcos/expl/nsc/lib/printf.html
> 
> I didn't know there were so many possibilities that were actually ANSI, 
> wonder what C99 etc says about this

What that document refers to as the the "type" field is a combination of 
  what C99 calls length modifiers and conversion specifiers.

C99 adds the following length specifiers: hh (signed char) ll (long 
long), j (intmax_t), z (size_t), t (ptrdiff_t). When combined with 
conversion specifiers for unsigned types, the first three all refer to 
the corresponding unsigned type.

C99 also adds two new conversion specifiers: a,A: hexadecimal floating point
0
Reply jameskuyper (5168) 9/27/2008 1:37:33 PM

3 Replies
32 Views

(page loaded in 1.784 seconds)

Similiar Articles:













7/8/2012 1:32:56 PM


Reply: