0

I've a textbox control on my ASP.NET page which accepts amount of Money. If it is entered as 500,after leaving the textbox control, I want to appear it as 500.00.Using textchanged event I couldn't solve the problem in C#.Hope javascript will do it.Can anyone help me out by providing the required javascript or any other way?

Sukanya
  • 1,041
  • 8
  • 21
  • 40
  • Do you use jQuery or some other javascript library? – lalibi Nov 17 '11 at 10:20
  • See this post http://stackoverflow.com/questions/477892/in-jquery-whats-the-best-way-of-formatting-a-number-to-2-decimal-places – Prasanth Nov 17 '11 at 10:27
  • possible duplicate of [How to write 5 as 5.00 on ASP.NET Page](http://stackoverflow.com/questions/8118213/how-to-write-5-as-5-00-on-asp-net-page) – sll Nov 17 '11 at 16:46

1 Answers1

0

You can try to do this in this fashion, make a javascript function and call it on the onblur event of the textbox

var txt ='5'; // ur value in textbox    
var decimalplace = new Number(parseFloat(txt)); // say you have values like 5.15747
alert(decimalplace.toFixed(2)); // gotta get 5.00
V4Vendetta
  • 37,194
  • 9
  • 78
  • 82
  • Thank u.It's working if there is no auto post back=true for any other control in the form.The moment another control's value is being changed,this textbox control is showing 0.00 .It's not holding back the previously entered amount. – Sukanya Nov 18 '11 at 12:25
  • ya,we are using viewstate to hold diffeterent state of the page. – Sukanya Nov 21 '11 at 10:31
  • Did the above thing help you achieve the format ? else please do key in your answer – V4Vendetta Nov 28 '11 at 11:06
  • yes,it helped me to dispaly the numberas I wanted to.thanks a lot. – Sukanya Nov 30 '11 at 08:39
  • If yes then do please mark this as answer, click on the check mark next to the answer .. will help for all those who stumble upon this later – V4Vendetta Nov 30 '11 at 08:41