I want to replace the value of a string. This is an integer but saved in string. Eg: i am getting the value as 123.345 the i need to get the value as 123 only. I want to replace value after . with '' but the issue is i don't know how many decimal place is coming after point. Please help me to solve this issue.
Attribution to: AnuRaj
Possible Suggestion/Solution #1
One easy way is to convert it first into a decimal number and then convert the decimal into an integer.
String myString = '123.123435';
Decimal myDecimal = Decimal.valueOf(myString);
Integer myInteger = Integer.valueOf(myDecimal);
System.debug(myInteger);
Attribution to: Joey Chan
Possible Suggestion/Solution #2
You can use
String myString = '123.123435';
String st = myString.substring(0, myString.indexOf('.') );
System.debug(st);
Attribution to: Prady
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1382