简体   繁体   English

格式化从网址提取的数据

[英]Formating data pulled from the url

I currently have a script that pulls a parameter from the url and displays on the page. 我目前有一个脚本,该脚本从url中提取参数并显示在页面上。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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