Parse and format a number to decimal in Java

Java 8Object Oriented ProgrammingProgramming

To parse and format a number to decimal, try the following code.

Example

 Live Demo

public class Demo {
   public static void main( String args[] ) {
      int val = Integer.parseInt("5");
      String str = Integer.toString(val);
      System.out.println(str);
   }
}

Output

5

In the above program, we have used the Integer.parseInt() and Integer.toString() method to convert a number to decimal.

int val = Integer.parseInt("5");
String str = Integer.toString(val);

The toString() method above represents a value in string and formats.

raja
Published on 13-Nov-2018 07:40:03
Advertisements