Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the easy way to show only 4 digits after decimal point by default inside textboxes in html

I have some textboxes which are bind to decimal fields of a view model in cshtml file. Most of them have nine zeros after decimal. I want to show only 4 digits by default while editing them. However, I don't want to fix the length after decimal. Can anyone help me with this?

like image 868
Exception handler Avatar asked Oct 25 '25 20:10

Exception handler


1 Answers

I suggest doing at c# controller or where you bind data to UI control like:

String.Format("{0:0.0000}", 123.456789012); // 123.4568

You can aslo do it in native javascript like :

var num = 123.456789012;
var n = num.toFixed(4); // 123.4568
like image 139
Pranav Singh Avatar answered Oct 28 '25 10:10

Pranav Singh