When I wanted to change the calculation method before and after the decimal point, I stumbled a little and solved it, so make a note of it.
Eclipse Neon 4.6.3 Java8
-Whether the character string contains a decimal point int variable name = string variable .indexOf ("character you want to look up");
-Getting the character string before and after the decimal point String variable .substring (x, y); x = position of the first character y = end character position (optional)
public class strPractice {
public static void main(String[] args) {
String a = "12345.6789";
//In a string"."Is included
//The location if included(Starting from 0)If not-Returns 1
int b = a.indexOf(".");
System.out.println((b + 1) + "It is included in the second.");
//Divide the searched character as the starting point
//first half
String c = a.substring(0 , b);
System.out.println("Characters to the decimal point" + c + "is.");
//Latter half
String d = a.substring(b + 1);
System.out.println("The characters after the decimal point are" + d + "is.");
}
}
Execution result
It is included in the 6th.
The character to the decimal point is 12345.
The character after the decimal point is 6789.
I used this method to convert a decimal number received in form to a binary number (because the decimal point calculation is special for binary numbers). I thought that I would normally use it as an address.
Recommended Posts