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
sd2008sd2008 

How to Convert Double to String?

I have a function which takes a string parameter, but the value is a Double from Salesforce.

How do I convert a Double to String?

AlsoDougAlsoDoug

From the apex documentation:

 

 

Double myDouble = 12.34; String myString = String.valueOf(myDouble);

 

 

 

 

 

sd2008sd2008
Thanks
sd2008sd2008

I got a "Comparison arguments must be compatible types: Double, String" error message

 

the Fn_outcall.saveobj(str) function takes a string parameter.

here is the code:

 

trigger OriUpdateTrigger on Ori__c (after insert, after update) {

 for(Ori__c o: Trigger.New){

  if (o.AID__c != null && o.AID__c <>''){   String str = String.valueOf(o.AID__c);

   Steven_Outcall.SaveOriginator(str);

  }

 }

}

a.schaefera.schaefer
if your variable o.AID__c is a double the comparison
o.AID__c
won't work
sd2008sd2008
thanks
jrojas-58demojrojas-58demo

I have this conversion:

String value = '6000';
String CR = String.valueOf(Double.valueOf(value) / 2.00000);
system.debug('CR: ' + CR);

 

and the developer console returns 

CR: 3E+3

 

but I want:
3000

jrojas-58demojrojas-58demo

after to review the documentation a good solution is:

String value = '6000';
String CR = (Double.valueOf(value) / 2.00000).format().remove(',');
system.debug('CR: ' + CR);