function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anu Raj.ax1269Anu Raj.ax1269 

Replacing string value

Hi

I want to replace the value of a string. This is a 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.

Thanks

Anu

Best Answer chosen by Admin (Salesforce Developers) 
Anu Raj.ax1269Anu Raj.ax1269

Hai thanks gays.. 

I found the solution 

 

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

All Answers

PremanathPremanath

Hi anu

This may helpful to you

 

Decimal d=123.345;
integer i=Integer.valueOf(d);
String s=String.valueOf(i);
System.Debug('-------->'+s);

 

 

if it helpful plz make solution as acceptable for others it may benfit

Teach_me_howTeach_me_how

string stringval = '123.345';
decimal decimalValue = decimal.valueof(stringval);
Integer integerValue = decimalValue.intValue();
string newval = string.valueof(integerValue) + '. any number or letter';
system.debug(newval);

Anu Raj.ax1269Anu Raj.ax1269

Thanks, you both are right and I have done the same but I need to do this by using string only not by converting into integer then to string again. Do anybody have any idea.

Anu Raj.ax1269Anu Raj.ax1269

Hai thanks gays.. 

I found the solution 

 

String myString = '123.123435';
String st = myString.substring(0, myString.indexOf('.') );
This was selected as the best answer
Teach_me_howTeach_me_how

string a = '123.456';
list<string> split_a = a.split('\\.');
system.debug(split_a[0]);