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
Balwant_SinghBalwant_Singh 

How To Format String

Hi All,

 

My problem is that. I have a double value in my controller and i converted it in to String like as;

Double value = 0.5268056142435206;

String str = String.ValueOf(value );

 

Now when i print this on page its comes like 0.5268056142435206 as i expected.

But my requirement is to print something like 0.52 on screen.

How i will achieve this?

Thanks in advance..

Darshan FarswanDarshan Farswan

You can use substring() funtion in order to get the desired number of characters from the sequence.

For 0.52, I think you have 4 characters. So this should work for you str.substring(0,4) where 0 is the start index and 4 is the end index.

 

Hoping this will work.