0

Possible Duplicate:
Javascript: formatting a rounded number to N decimals

I'm modifying a label text using JavaScript

I need to format that label text in the form (ex: 45.00). Now it is being displayed as (45)

How can I achieve this from client side

To accomplish this from server side, I'm doing - lb.Text = String.Format("{0:0.00}", rondedamount);

I need this from client side (Inside Label) or from JavaScript.

Community
  • 1
  • 1
Krishna Thota
  • 6,646
  • 14
  • 54
  • 79
  • I guess you know how to get and set element value use javascript, than with the function metioned here: http://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format, it should be fairly easy. – Baiyan Huang Aug 17 '12 at 16:51

2 Answers2

1

this may work for you :

var num = 45;
formated_num = num.toFixed(2);
console.log(formated_num);

The toFixed() method converts a number into a string, keeping a specified number of decimals. where the toPrecision, Returns a string representing a Number object in fixed-point or exponential notation rounded to precision significant digits.

Shreedhar
  • 5,502
  • 3
  • 22
  • 27
1
var num = 45;
alert(num.toFixed(2));
Diode
  • 24,570
  • 8
  • 40
  • 51