我想将十进制 4.4589 解析为 4.45。但是,我不可能成功。我试过用parseFloat(yourString).toFixed(2)但它没有用...请帮我解析“BanknoteBuying”和“BanknoteSelling”。提前致谢[HttpGet]public ActionResult GetData(){ XDocument doc = XDocument.Load("http://www.tcmb.gov.tr/kurlar/today.xml"); var dox = doc.Descendants() .Where(r => r.Name == "Currency") .Select(r => new { Isim = r.Element("Isim").Value, Kod = r.Attribute("Kod").Value, AlisKur = r.Element("BanknoteBuying").Value, SatisKur = r.Element("BanknoteSelling").Value }).Where(x=>x.Isim== "ABD DOLARI"||x.Isim== "EURO"); return Json(dox, JsonRequestBehavior.AllowGet);}
1 回答
繁花不似锦
TA贡献1851条经验 获得超4个赞
var yourString = "4.4589";
var result = Math.trunc(parseFloat(yourString) * 100) / 100;
console.log(result);
- 1 回答
- 0 关注
- 133 浏览
添加回答
举报
0/150
提交
取消