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 人气:208
分享到:
blog comments powered by Disqus

相关文章

  • Javascript四舍五入Math.round()与Math.pow()使用介绍 2014-07-09

    本文为大家介绍下Javascript中的四舍五入Math.round()与Math.pow()的使用,感兴趣的朋友不要错过 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/x

  • Javascript四舍五入(Math.round()与Math.pow()) 2013-07-11

    代码 Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> &

  • Daquan js, javascript code, js code integration 2010-12-22

    Event source object event.srcElement.tagName event.srcElement.type Capture Release event.srcElement.setCapture(); event.srcElement.releaseCapture(); Events button event.keyCode event.shiftKey event.altKey event.ctrlKey Event return values event.retur

  • javascript achieve trim () function 2009-07-17

    javascript does not provide the trim () function, through the following regular expression to achieve trim () function; Principle: The realization of the principle of the trim () function if the string at the beginning of the end of the blank charact

  • javascript simple example of a collection 2009-11-15

    Simple to verify: <form name="myform"> User Name: <input type="text" name="username"/> <br /> Password: <input type="password" name="password" /> <br /> <button> landing

  • Summary of the Basics javascript 2010-10-04

    1. Structure: <script type="text/javascript"> ............... </script> Or the following structure (in the W3C HTML standards, is no longer recommended) <script language="javascript"> ............... </script> 2

  • Javascript 多物体运动的实现 2013-12-04

    这篇文章主要介绍了Javascript 多物体运动的实现,需要的朋友可以参考下 我们先来看下之前的运动的代码,是否支持多物体运动,会出现怎么样的问题. <style type="text/css"> div { width: 100px; height: 50px; background: red; margin: 10px; } </style> 复制代码 代码如下: <body> <div></div> <div&g

  • JavaScript制作简易的微信打飞机 2014-02-05

    这篇文章主要介绍了JavaScript制作简易的微信打飞机,只有简单的功能,大神们可以自由扩展哈.有需要的小伙伴可以参考下. 简单的用JavaScript模拟微信打飞机,部分功能还不完善,刚开始写,还有很多不足,还望大家多多指出. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html&g

  • JavaScript中valueOf函数与toString方法深入理解 2014-04-13

    基本上,所有JS数据类型都拥有valueOf和toString这两个方法,null除外.它们俩解决javascript值运算与显示的问题,本文将详细介绍,有需要的朋友可以参考下 JavaScript中valueOf函数方法是返回指定对象的原始值.使用方法: object.valueOf( )object是必选项参数是任意固有 JScript 对象. 每个JavaScript固有对象的 valueOf 方法定义不同. 对象 返回值 Array 数组的元素被转换为字符串,这些字符串由逗号分隔,连接在

  • javascript圆盘抽奖程序实现原理和完整代码例子 2014-06-05

    这篇文章主要介绍了javascript圆盘抽奖程序实现原理和完整代码例子,需要的朋友可以参考下 效果预览: 一.模拟抽奖的实现过程 旋转原理:当支持CSS3属性采用transform: rotate(角度deg)设置,当角度为正数时顺时针旋转,当为负数时逆时针旋转.如果是IE8及其以下,采用采用绝对定位设置top和left,模拟角度旋转. run方法,参数angle指角度 function run(angle) { if (isIE) { cosDeg = Math.cos(angle * Ma

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

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

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

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