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
Updated on 26-Jun-2020 07:26:09