手记

字符串与基本数据之间的转换

String number1 = "123.45";
    float num1 = Float.parseFloat(number1);  //String to Float
    String numb1 = String.valueOf(num1);   //float to String
    System.out.println("String:"+numb1);  //
    System.out.println("Float:"+num1); 
    String number2 = "100";  
    int num2 = Integer.parseInt(number2);  //String to int
    Long num22 = (long)num2;  //int to long
    System.out.println(Long.toString(num22,2));  //long to binaryString
    System.out.println(Long.toString(num22,8));  
    System.out.println(Long.toString(num22,16));  
0人推荐
随时随地看视频
慕课网APP