+ Start a Discussion
MigMig 

Convert a Picklist value to a Double value

I made a trigger that updates somes values after update. But some fields are not the same type.

Is there any functionnality ( like toString)  to covnert My picklist values (String) to a double ( Like parseFloat in Javascript).


Thank you
Best Answer chosen by Admin (Salesforce Developers) 
Rajesh ShahRajesh Shah
Found the way to do it.

Double d = Double.valueOf( str ); // str is the string u need to convert

Similar method is also available for converting string to long, integer, decimal, ...


Message Edited by Rajesh Shah on 05-22-2008 02:22 AM

All Answers

Rajesh ShahRajesh Shah
Hi,
Even I want to implement the same functionality i.e to convert a string to a double.
I looked into the Apex Language Reference String methods but couldnt any such function.

Is there any other way to do it?
mba75mba75
The Apex User guide give us : integer.Format

But as usual no example  So i did the following

for (OpportunityLineItem oli : trigger.new   ){

string B=oli.Billing_Term__c;

integer m = B.Integer.Format;}


and I get the following error message Error: Compile Error: Initial term of field expression must be a concrete SObject: String

Tell me if that works  for you ?


Rajesh ShahRajesh Shah
I used Integer.Format .
It again gives the same error "Compile Error: Initial term of field expression must be a concrete SObject:"
Rajesh ShahRajesh Shah
Found the way to do it.

Double d = Double.valueOf( str ); // str is the string u need to convert

Similar method is also available for converting string to long, integer, decimal, ...


Message Edited by Rajesh Shah on 05-22-2008 02:22 AM
This was selected as the best answer
mba75mba75
It works for thanks you

Integer.valueof(B)

MigMig
Wow .. cool It seems that works fine also ...
Thank you very much !
dmchengdmcheng
.format() is used for converting numeric into string values.
bca321bca321

 Convert string to decimal type:

 

is this correct

 

 

Decimal DebitAmount = decimal.valueOf('');

Rajesh ShahRajesh Shah

Yes, it is correct. Check the following example from Apex Lang Reference

 

 String temp = '12.4567';
Decimal myDecimal = Decimal.valueOf(temp);