English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Analizzare un numero e formattarlo in decimale in Java

Per interpretare un numero e impostarlo in formato decimale, provare il seguente codice.

Esempio

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

Risultato di output

5

Nel programma sopra, abbiamo utilizzato i metodi Integer.parseInt() e Integer.toString() per convertire i numeri in decimale.

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

toString()Il metodo sopra descritto rappresenta un valore come stringa e formato.