---
title: "js 保留小数后1位或2位"
author: "yanyanquan"
date: "2012-05-23T11:01:43Z"
tags: []
categories: ["Web前端"]
slug: "js-1-2"
draft: false
lastmod: "2012-05-23T11:01:52Z"
id: 1538419
url: "https://kwon.iteye.com/blog/1538419"
---

function changeTwoDecimal(x)  
{  
var f\_x = parseFloat(x);  
if (isNaN(f\_x))  
{  
return false;  
}  
var f\_x = Math.round(x\*10)/10;

return f\_x;  
}