Javascript interception of decimal places and rounded

sponsored links
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>
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Javascript interception of decimal places and rounded

  • Hibernate primary key strategy-sequence

    Today, the use of hibernate in the company encountered a troublesome problem, the use of hibernate when the primary key generation strategy set sequence, but always reported in the implementation could not get next sequence value of the error, then o ...

  • hibernate call stored procedure

    hibernate call stored procedure

  • hibernate using c3p0 connection pooling

    Private c3p0 for open source's JDBC connection pool, with the release hibernate. This article describes how to use the hibernate configuration in c3p0. c3p0 connection pool configuration is v ...

  • Hibernate configuration parameters

    Hibernate in the configuration file: <properties> <property name="" value="create" /> </ properties> Parameter Description: validate load hibernate, the authentication to create a database t ...

  • Build flex + spring + blazeds + hibernate application

    Build flex + spring + blazeds + hibernate application First, set up the project blazeds 1, will blazeds.war extract to a directory, such as: myflex /; 2, set up java works were such as: MyFlex, in the orientation of selection create project from exis ...

  • Hibernate connection pool configuration

    Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @

  • hibernate generic generic DAO

    package org.lzpeng.dao; import; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • Hibernate secondary cache

    Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries