The digital val rounding, and retain the decimal scale

/**
 * The val rounded  , And retain scale decimal
 */
function mathRound(val,scale){
    var base = 10;
    for(var i=1;i<scale;i++){
        base = base*10;
    }
    var newVal = Math.round(val*base)/base;
    var rsplit = newVal.toString().split(".");
    var zeroNum = scale;
    if(rsplit[1]){
        zeroNum = scale-rsplit[1].length;
    }
    if(zeroNum==scale){
        newVal = newVal+".";
    }
    for(var i=0;i<zeroNum;i++){
        newVal = newVal+"0";
    }
    return newVal;
}
分类:Web 时间:2009-09-03 人气:215
本文关键词: lt math decimal scale
分享到:
blog comments powered by Disqus

相关文章

  • POJ 1894 Alternative Scale of Notation [JAVA operation of large numbers] 2010-05-31

    Alternative Scale of Notation Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1530 Accepted: 538 Description One may define a map of strings over an alphabet Σ B = (C1, C2,... C B) of size B to non-negative integer numbers, using characters as

  • CallableStatement Xiangjie 2010-09-16

    CallableStatement for the implementation of SQL stored procedures. JDBC provides a stored procedure SQL escape, it allows a standard way for all RDBMS stored procedure call. This escape syntax has a result parameter that contains the format and a for

  • Detailed CallableStatement 2010-09-16

    CallableStatement is used to execute SQL stored procedures. JDBC provides a stored procedure SQL escape, which allows a standard way to call all RDBMS stored procedures. This escape syntax has one parameter that contains the format and the result doe

  • Common abnormalities resolved 2011-09-18

    ConcurrentHashMap and CopyOnWriteArrayList comparison. Blog categories: Java ConcurrentHashMap ConcurrentHashMap introduced Segment, each Segment is a hashtable, the equivalent of two Hash table, and then lock in the Segment level, and increased concurren

  • EJB 2009-02-27

    public transient int counter; / / transient property private String firstname; / / persistent property @ Transient String getLengthInMeter () (...) / / transient property String getName () (...) / / persistent property @ Basic int getLength () (...) / / p

  • hibernate annontaion learn more 2010-04-07

    Hibernate Annotation Description Turn http://relucent.javaeye.com/ @ Entity public class Flight implements Serializable ( Long id; @ Id public Long getId () (return id;) public void setId (Long id) (this.id = id;) ) @ Entity annotation to a class declarat

  • Image processing tools 2010-04-12

    In actual projects, we often encounter a variety of image processing problems. For example: image rotation, zooming, image format conversion, get image type, image size validation, write pictures. Here we use java.awt.Graphics2D to achieve common ima ...

  • HIbernate comment Xiangjie 2010-05-16

    @ Author liuguangyi @ Content ejb3 annotation of the API defined in the javax.persistence .* package inside. Note Note: @ Entity - a class declared as an entity bean (ie a persistent POJO class) @ Id - Note statement of the identity of the entity bean att

  • android marker zoom with map 2010-10-25

    Martix by android.graphics.Matrix to set the picture in size. Question 1: How to save the picture after scaling? Question 2: how to google map to zoom to set the marker of the zoom level? With these two issues, we should look at how to do next in the end.

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

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

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

processed in 0.091 (s). 15 q(s)