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?
Asked
Active
Viewed 294 times
0
-
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 Answers
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
-
-
Did the above thing help you achieve the format ? else please do key in your answer – V4Vendetta Nov 28 '11 at 11:06
-
-
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