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
davidjbbdavidjbb 

setScale

Hello,

 

I need help with the following setScale, not sure why it's not working. I need to be able to set certain number fields with trailing 0. In this case I need a trailing 4 decimal places even if it's 0

 

quantity__c is Number(18, 0) (I had it set to 14,4..nothing changed)

 

m.quantity__c = (m.quantity__c).setScale(4);

 

The value would appear as ie. 10.0

 

If m.quantity__c was a string field I believe the setScale(4) works but i dont want to create unnecessary fields..

Best Answer chosen by Admin (Salesforce Developers) 
colemabcolemab

@davidjbb  The fact that salesforce doesn't honor the scale setting (for values ending in zeros) in the database is an old issue that I previously documented here.

 

Hope this helps.

All Answers

kentylerkentyler
you could try changing the number to a string in your code integer i=123; string s1=string.valueof(i); if setScale works for strings, then you would have a string to pass to it ken tyler
davidjbbdavidjbb

m.quantity__c is a released field, I can't change it from Number to a String field.

colemabcolemab

@davidjbb  The fact that salesforce doesn't honor the scale setting (for values ending in zeros) in the database is an old issue that I previously documented here.

 

Hope this helps.

This was selected as the best answer