%g displays a floating-point number in either the %f or %e (scientific) format, depending on which is shorter. : float Display « Data Type « C Tutorial

Home
C Tutorial
1.Language
2.Data Type
3.String
4.printf scanf
5.Operator
6.Statement
7.Array
8.Function
9.Structure
10.Pointer
11.Memory
12.Preprocessor
13.File
14.Data Structure
15.Search Sort
16.Wide Character String
17.assert.h
18.ctype.h
19.math.h
20.setjmp.h
21.signal.h
22.stdio.h
23.stdlib.h
24.string.h
25.time.h
26.wctype.h
C Tutorial » Data Type » float Display 
2.20.6.%g displays a floating-point number in either the %f or %e (scientific) format, depending on which is shorter.
#include <stdio.h>
main(){
   
    printf("%g"123456.123456);
    printf("\n%g"6.1);

}
123456
      6.1
2.20.float Display
2.20.1.Displaying Floating-Point Data Types with printf: %f
2.20.2.To create precision with floating-point numbers
2.20.3.%6f limits the output to only six digits
2.20.4.%e displays numbers in scientific format.
2.20.5.use the %E in printf() to display scientific-notation numbers
2.20.6.%g displays a floating-point number in either the %f or %e (scientific) format, depending on which is shorter.
2.20.7.Printing floating-point numbers with floating-point conversion specifiers
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.