<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[javascript 小数类型格式化]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Tue, 12 May 2015 02:52:25 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	背景：做温控，存在小数位数设置到整数时，没有小数后一位，需要补齐，于是格式化势在必行，像c有sprintf，javascript还不清楚，于是查了下，也有类似的函数来实现这样的功能：i1.toFixed(1)，也就是：$(&quot;#controlTempValue&quot;).html(toFixed(setTempRature,1));。<br/>——————————————————————————————————————————————————————————<br/><textarea name="code" class="php" rows="15" cols="100">
var a=3.1415926;
a = a.toFixed(2);//保留2位但结果为一个String类型
a = parseFloat(a);//将结果转换会float
//用一步的话如下
a = parseFloat(a.toFixed(2));
</textarea><br/><br/>如果出现：ToFixed() Is Not A Function?<br/>TypeError: setTempRature.toFixed is not a function&nbsp;&nbsp;<br/>var setTempRatureDisplay = setTempRature.toFixed(1);<br/>使用toFixed对小数四舍五入的时候，弹出以下错误提示：<br/><br/>toFixed() is not a function<br/>后来还是在stackoverflow上找到了答案<br/><br/>toFixed isn’t a property of non-numeric variable types. In other words, Low and High can’t be fixed because when you get the value of something in Javascript, it automatically is set to a string type. Using parseFloat() (or parseInt() with a radix, if it’s an integer) will allow you to convert different variable types to numbers which will enable the toFixed() function to work.<br/>var Low = parseFloat($SliderValFrom.val()),<br/>var High = parseFloat($SliderValTo.val());<br/>原来toFixed只能针对数字类型才能使用，所以对于字符类型的要用parseFloat或者parseInt函数先转一下再调用<br/>摘自：http://www.jason-z.com/tofixed-is-not-a-function/<br/>——————————————————————————————————————————————————————————<br/>在客户js中,我们时常会碰到处理这样的小数类型(转换为字符串):<br/><br/>var i = 1234.8700<br/><br/>document.write(&quot;i&quot;)&nbsp;&nbsp;//结果:1234.87&nbsp;&nbsp; 我们想要的结果是1234.8700<br/><br/>也就是小数的有效位数为4位.js中有一个处理这种情况的函数,toFixed(小数有效位数).<br/><br/>如:<br/><br/>var i1 = 3456.244280;<br/>alert(i1.toFixed(2)); // 输出 1024.24<br/><br/>var i2 = 3456.24558;<br/>alert(i2.toFixed(2)); // 输出 1024.25<br/><br/>var i3 = 3456.2;<br/>alert(i3.toFixed(2)); // 输出 1024.20<br/><br/>摘自：http://www.cnblogs.com/rainnight/archive/2009/02/10/1387483.html
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] javascript 小数类型格式化]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>