1

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.

1

You can use

String myString = '123.123435';
String st = myString.substring(0, myString.indexOf('.') );
System.debug(st);
| improve this answer | |
3

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);
| improve this answer | |

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.