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.


You can use

String myString = '123.123435';
String st = myString.substring(0, myString.indexOf('.') );

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.