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
uptime_andrewuptime_andrew 

Print Double to 1 Decimal Place

Hello,

 

How can I print a Double on my VF page to one decimal place?  Using format returns the number with 3 decimal points.

 

AT

 

ScoobieScoobie

This can be very easy depending on whether you need it to be a double on the page.

 

You can cast it to a string and use (''+myDouble).substring(0, string.indexOf('.')+1) which should take the string up to the char after the decimal point

 

I don't think there is an Apex equivalent of the Decimal Formatter to use.

uptime_andrewuptime_andrew

Thanks Scoobie!

kxa422kxa422

May be something like that

 

 

 

<apex:outputText value="{0, Number, #0.0}">

<apex:param value="{!Price__c}" />

</apex:outputText>

 

 

GuyClairboisGuyClairbois

You can also use decimal for this function.

 

 

Decimal vol = yourDouble;
Decimal volRounded = vol.divide(1,3,System.RoundingMode.Up);

 

"3" indicates the amount of decimals to be used. System.RoundingMode defines how to round the double.

 

See the documentation on decimals for more information.

Rgrds,

Guy