简体   繁体   中英

Formating data pulled from the url

I currently have a script that pulls a parameter from the url and displays on the page. My problem is that I need to format the decimal place for the value.

UPDATED (This is working now. Thank you all.)

Code

$(document).ready(function () {

var url = $.url('https://www.google.com/blah/blahblah/index.htm?x=50.5200');

var x = url.param('x');

var x2 = parseFloat(x).toFixed(2);

 $("#value").text(x2);

});

Try this:

var decimal = '50.5230';
var num = parseFloat(decimal).toFixed(2);
console.log(num);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM