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
sheila srivatsavsheila srivatsav 

keep two zeroes after decimal point javascript

I am not very good in javascript

I have a lightning component and in the controller.js file I have as shown below

var uos=claimlines.unitofservice;

when I debug this it returns a value of 30.0000

My client has told me to keep only two zeroes after the decimal point,

A working code would be greatly helpful.

thanks
sheila
 
Best Answer chosen by sheila srivatsav
Maharajan CMaharajan C
Hi Sheila,

Try the below one:

var uos=claimlines.unitofservice;
var x = uos;
x = Math.floor(x * 100) / 100;
alert(x.toFixed(2)); 

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Maharajan.C

All Answers

Maharajan CMaharajan C
Hi Sheila,

Try the below one:

var uos=claimlines.unitofservice;
var x = uos;
x = Math.floor(x * 100) / 100;
alert(x.toFixed(2)); 

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Maharajan.C
This was selected as the best answer
Deepali KulshresthaDeepali Kulshrestha
Hi Sheila,

Please try this code to achieve two values after  decimal.

  var num = 30.0000;
  var n = num.toFixed(2);
  where The toFixed() method converts a number into a string, keeping a specified number of decimals.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha