in javascript how to get only two decimal places?

Cases sum = parseFloat (8.99) + parseFloat (7.50);
Wait until the value is: 16.4900000002
How to get only two decimal places?

<script language="JScript">
Number.prototype.toFixed = function (num)
(
/ / Re-structure toFixed method, IE5.0 +
with (Math) this.NO = round (this.valueOf () * pow (10, num)) / pow (10, num);
return String (/ \. / g.exec (this.NO)? this.NO: this.NO +"."+ String (Math.pow (10, num)). substr (1, num));
)
alert ((12.9299). toFixed (2));
alert ((12.9999). toFixed (2));
</ script>

. toFixed (2) can not seem to rounding

分类:AJAX 时间:2009-08-16 人气:798
分享到:
blog comments powered by Disqus

相关文章

  • Oracle function Daquan (string functions, math functions, date functions, logical functions, other functions) 2010-12-09

    Oracle function Daquan (string functions, math functions, date functions, logical functions, other functions) Keywords: Oracle Functions String Functions Date Functions Mathematical Functions logical function SQL functions in a single record 1.ASCII

  • Oracle functions Daquan (string functions, math functions, date functions, logical functions, other functions) 2010-12-09

    Oracle functions Daquan (string functions, math functions, date functions, logical functions, other functions) Keywords: Oracle Functions String Functions Date Functions math logic operation function SQL functions in a single record 1.ASCII Returns t

  • Oracle functions Daquan (string functions, math functions, date functions, logical functions, other functions) [switch] 2011-06-14

    Oracle functions Daquan (string functions, math functions, date functions, logical functions, other functions) [switch] SQL functions in a single record 1.ASCII Returns the character corresponding to the specified decimal number; SQL> select ascii ('

  • Implementation in javascript string trim () 2009-04-25

    <script language="javascript"> String.prototype.Trim = function () ( return this.replace (/ (^ \ s *) | (\ s * $) / g, ""); ) </ script>

  • JS string correlation method 2010-05-01

    Go to space: <script type="text/javascript"> function trim (str) (/ / Remove the spaces around both ends return str.replace (/ (^ \ s *) | (\ s * $) / g, ""); ) function ltrim (str) (/ / Remove the spaces left return str.replace

  • Adding Javascript object for the String Trim () method 2010-10-09

    Each object using Javascript (Object) of the prototype attributes we can add Javascript built-in objects in our own methods and properties. The following we will use this property to add three methods for the String object: Trim, LTrim, RTrim (role a

  • 在Javascript中为String对象添加trim,ltrim,rtrim方法 2014-01-03

    利用Javascript中每个对象(Object)的prototype属性我们可以为Javascript中的内置对象添加我们自己的方法和属性. 以下我们就用这个属性来为String对象添加三个方法:Trim,LTrim,RTrim(作用和VbScript中的同名函数一样) String.prototype.Trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); } String.prototype.LTrim = f

  • String.prototype实现的一些javascript函数介绍 2014-11-18

    这篇文章主要是对String.prototype实现的一些javascript函数进行了详细的介绍,需要的朋友可以过来参考下,希望对大家有所帮助 //String.prototype使用 //批量替换,比如:str.ReplaceAll([/a/g,/b/g,/c/g],["aaa","bbb","ccc"]) String.prototype.ReplaceAll=function (A,B) { var C=this; for(var i=0

  • javascript截取字符串小结 2014-01-04

    本文章收藏了多种字符截取的方法,包括常用的js截取字符串,截取字符串函数及常用的截取使用,非常的简单实用,有需要的小伙伴可以参考下. 本文总结介绍了三种使用Javascript截取字符串的方法,同时也总结了两种截取中文字符串的办法,分享一下. 1.substring 方法 定义和用法 substring 方法用于提取字符串中介于两个指定下标之间的字符. 语法 stringObject.substring(start,stop) 参数 描述 start 必需.一个非负的整数,规定要提取的子串的第一

  • JSP request(return String)用法详例 2014-08-25

    JSP中request(return String)用法详例 ,需要的朋友可以参考下. 1.JSP代码 : <%-- Document : index Created on : 2009-10-4, 12:45:43 Author : lucifer --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.036 (s). 13 q(s)