Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Floating-point conversion characters in Java
Floating-point conversion characters include the following.
| Character | Description |
|---|---|
| %e | decimal number in computerized scientific notation |
| %E | decimal number in computerized scientific notation |
| %f | decimal number |
| %g | based on computerized scientific notation or decimal format, |
| %G | based on computerized scientific notation or decimal format, |
Example
public class Demo {
public static void main(String[] args) throws Exception {
System.out.printf("Integer conversions...\n");
System.out.printf( "Integer: %d\n", 889 );
System.out.printf( "Negative Integer: %d\n", -78 );
System.out.printf( "Octal: %o\n", 677 );
System.out.printf( "Hexadecimal: %x\n", 56 );
System.out.printf( "Hexadecimal: %X\n", 99 );
System.out.printf("\nFloating-point conversions...\n");
System.out.printf( "%e\n", 29567457.78 );
System.out.printf( "%E\n", 34567457.89 );
System.out.printf( "%f\n", 69874789.11 );
System.out.printf( "%g\n", 7567579.38 );
System.out.printf( "%G\n", 4766757.67 );
}
}
Output
Integer conversions... Integer: 889 Negative Integer: -78 Octal: 1245 Hexadecimal: 38 Hexadecimal: 63 Floating-point conversions... 2.956746e+07 3.456746E+07 69874789.110000 7.56758e+06 4.76676E+06
Advertisements