Convert octal number to decimal number in Java

Java 8Object Oriented ProgrammingProgramming

To convert octal to decimal number, use the Integer.parseInt() method with radix 8. Here, the radix is for Octal i.e. 8.

Let’s say we have the following octal string.

String myOctal = "25";

To convert it to decimal, use the Integer.parseInt() method.

int val = Integer.parseInt(myOctal, 8);

The following is the complete example.


 Live Demo

public class Demo {
   public static void main(String []args) {
      String myOctal = "25";
      System.out.println("Octal = "+myOctal);
      int val = Integer.parseInt(myOctal, 8);
      System.out.println("Decimal = "+val);


Octal = 25
Decimal = 21
Published on 10-Dec-2018 12:48:04