A.T. A.T. - 26 days ago 15
TypeScript Question

toString float number in javascript

In below snippet, how can I show message

Min value is 0.00000001.


rather than

Min value is 1e-8




var minValue = 0.00000001;

var message = "Min value is " + minValue.toString();

var content = $('p#content').text(message);

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="content"></p>




Answer

Use Number#toFixed or use a string instead of Number.

var minValue = 0.00000001;

var message =  "Min value is " +  minValue.toFixed(8);

var content = $('p#content').text(message);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="content"></p>

Comments