Javascript interception of decimal places and rounded

round method

Role: to return and give expression to the nearest integer value.
Syntax: Math.round (number), will be option number parameter is rounded to the nearest integer value.
Note: If the number is greater than equal to the fractional part of 0.5, the return value is the smallest integer greater than the number. Otherwise, round number to return the largest integer less than or equal.

/ / If you take one then multiplied by 10 divided by 10 after, and so on
Math.round (3.248 * 100) / 100

Javascript 1.5 new functions

In Javascript 1.5 (IE5.5 +, NS6 + or later support), the addition of two special functions for the circulation of money:
Number.toFixed (x) and Number.toPrecision (x).

Number.toFixed (x) is the interception of the specified number of decimal places x, Number.toPrecision (x) is to specify the number of intercept (x) length. Note that one is to calculate the length after the decimal point, one is calculating the length of the entire number.

<script type="text/javascript">
var aa = 2.3362;
document.write (aa.toFixed (1)); / / 2.3
document.write (aa.toFixed (2)); / / 2.34
document.write (aa.toPrecision (2)); / / 2.3
document.write (aa.toPrecision (3)); / / 2.34
document.write (Math.round (aa * 10) / 10); / / 2.3
document.write (Math.round (aa * 100) / 100); / / 2.34
</ Script>

分类:Web 时间:2010-05-05 人气:196
分享到:
blog comments powered by Disqus

相关文章

  • JavaScript's regular expression parsing 2010-07-12

    Regular expression is a character model describing the object. JavaScript's RegExp object and String object is defined using regular expressions to perform powerful pattern matching and text search and replace functions. In JavaScript, regular expres

  • Some elements of JavaScript array interception 2010-12-01

    Some elements of JavaScript array interception slice () method for the Array object as a substring () method for a String object. This method is simply to tell what elements you want to intercept. This is very useful, for instance, use the URL when y

  • [Change] common JavaScript validation regular expression 2010-06-01

    [Change] common JavaScript validation regular expression Chinese characters matching the regular expression: [u4e00-u9fa5] Comment: The match is a headache for the Chinese really do, with this expression is easier to handle Matching double-byte chara

  • nginx gzip duplicate MIME type "text / html" 2010-09-14

    Instruction [# Gzip gzip] [# Gzip_buffers gzip_buffers] [# Gzip_comp_level gzip_comp_level] [# Gzip_min_length gzip_min_length] [# Gzip_http_version gzip_http_version] [# Gzip_proxied gzip_proxied] [# Gzip_types gzip_types] After the upgrade to the l

  • JavaScript string interception and consolidation of 2010-12-23

    JavaScript and consolidation of the interception of a string 2010-08-13 String intercept JavaScript provides two methods interception strings, respectively, slice () and substring (). slice and substring can accept one or two parameters, 1 parameter

  • JavaScript Math.floor方法(对数值向下取整) 2014-01-11

    这篇文章主要介绍了Math.floor 方法用于对数值向下取整,即得到小于或等于该数值的最大整数,需要的朋友可以参考下 JavaScript Math.floor 方法Math.floor 方法用于对数值向下取整,即得到小于或等于该数值的最大整数.语法如下: Math.floor(x) 参数说明: 参数 说明 x 必需.必须是一个数值. 提示:该方法与 Math.ceil 方法正好相反. Math.floor 方法实例 <script language="JavaScript"&

  • JavaScript Math.ceil 方法(对数值向上取整) 2014-02-04

    js Math.ceil用于对数值向上取整,即得到大于或等于该数值的最小整数,需要的朋友可以参考下 JavaScript Math.ceil 方法Math.ceil 方法用于对数值向上取整,即得到大于或等于该数值的最小整数.语法如下: Math.ceil(x) 参数说明: 参数 说明 x 必需.必须是一个数值. 提示:该方法与 Math.floor 方法正好相反. Math.ceil 方法实例 <script language="JavaScript"> document.

  • JavaScript Math Object Reference Manual prototype property 2009-04-08

    JavaScript prototype property Return JavaScript Math Object Reference Manual (directory) The definition and use of prototype property can be added to the object properties and methods. Math object is not as Date and String objects as are the class, t

  • 如何用正则取input type="text"中的value 2014-02-04

    1.如何通过正则取input type="text"中的value呢? 2.如何过滤掉input type="checkbox"的标签? 这样只能达到正则取input type="text"中的value可是不能过滤掉input type="checkbox"的标签! alert [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] alert [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 解决: aler

  • JavaScript Math.ceil() 函数使用介绍 2014-08-17

    Math.ceil(x) -- 返回大于等于数字参数的最小整数(取整函数),对数字进行上舍入,下面有个不错的示例,感兴趣的朋友可以参考下 Math.ceil(x) -- 返回大于等于数字参数的最小整数(取整函数),对数字进行上舍入 ceil是ceiling的缩写,中文"上限"的意思 引用网址:http://www.dreamdu.com/javascript/Math.ceil/ ceil函数语法 Math.ceil(x); ceil函数参数 x -- 为number类型的数字 cei

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

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

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.313 (s). 12 q(s)