string.format("%.4f",1/3) 1.Math.Round(0.333333,2);//按照四舍五入的国际标准2. double dbdata=0.335333; string str1=String.Format("{0:F}",dbdata);//默认为保留两位3. float i=0.333333; int j=(int)(i * 100); i = j/100;4. decimal.Round(decimal.Parse("0.3…
关于Oracle中查询的数字值的显示格式需要保留小数点后两位(或者三位,及其... 方法一:使用to_char的fm格式,即: to_char(round(data.amount,2),'FM9999999999999999.00') as amount 不足之处是,如果数值是0的话,会显示为.00而不是0.00. 另一需要注意的是,格式中小数点左边9的个数要够多,否则查询的数字会显示为n个符号“#”. 解决方式如下: select decode(salary,0,'0.00',(to_char…
格式化浮点数的问题,用format(col,2)保留两位小数点,出现一个问题,例如下面的语句,后面我们给出解决方法 SELECT FORMAT(12562.6655,2); 结果:12,562.67 查看文档:Formats the number X to a format like '#,###,###.##', rounded to D decimal places, and returns the result as a string. If D is 0, the result has…
例如: var a = 1.335; alert(a.toFixed(2)) // IE 1.34 //chorme 1.33 若a为字符串,则需要先转换为Number类型 如: n = Number(a).toFixed(2) toFixed它是一个四舍六入五成双的诡异的方法(也叫银行家算法),"四舍六入五成双"含义:对于位数很多的近似数,当有效位数确定后,其后面多余的数字应该舍去,只保留有效数字最末一位,这种修约(舍入)规则是“四舍六入五成双”,也即“4舍6入5凑偶”这里“四”是指…
input内强制保留小数点后两位 位数不足时自动补0 小数点后位数超出2位时进行四舍五入 需引入jquery包 1.11.2版本 1 function xiaoshu(x) 2 { 3 var f = parseFloat(x); 4 var f = Math.round(x*100)/100; 5 var s = f.toString(); 6 var rs = s.indexOf('.'); 7 if (rs < 0) { 8 rs = s.length; 9 s += '.'; 10 }…
floor 返回不大于的最大整数 round 则是4舍5入的计算,入的时候是到大于它的整数round方法,它表示“四舍五入”,算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下取整,所以,Math.round(11.5)的结果为12,Math.round(-11.5)的结果为-11. ceil 则是不小于他的最小整数 看例子   Math.floor Math.round Math.ceil 1.4 1 1 2 1.5 1 2 2 1.6 1 2 2 -1.4 -2 -1…
1.限制只能输入正数和小数保留小数点后两位 1 <input type="number" id="txtNum" /> 2 3 <script type="javascript"> 4 $(function(){ 5 $("#txtNum").keyup(function () { 6 $(this).val(ChangeNumValue($(this).val())); 7 }); 8 9 10 })…
1.给文本框添加一个onkeyup=’clearNoNum(this)’点击事件 2.建立clearNoNum方法 function clearNoNum(obj) { obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符 obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字而不是 obj.value…
有时候在做数据处理的时候,在前台页面上显示的数字需要保留小数点的后两位,不足两位的用0代替,这个时候就需要对数据做一些处理了.如果只用round(value,2)(四舍五入)和trunc(value,2)(不四舍五入)这两个函数中的任意一个的话,会有些许缺陷.就是在尾数为0的时候,这个0会被省略掉.比如round(1/2,2) ,结果是0.5,而不是想要的0.50,这个时候就要想其它办法了. 一.在sql中做处理 ①.CAST (expression AS data_type) 参数说明: ex…
<script language="JavaScript" type="text/javascript"> function clearNoNum(obj){ obj.value = obj.value.replace(/[^\d.]/g,""); //清除“数字”和“.”以外的字符 obj.value = obj.value.replace(/\.{,}/g,"."); //只保留第一个. 清除多余的 obj.v…
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>floatDecimal.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta htt…
<%@include file="/WEB-INF/jsp/common/common.jsp" %> <title>价格录入限定</title> <script type="text/javascript"> /** * 实时动态强制更改用户录入 * arg1 inputObject **/ function amount(th) { var regStrs = [ [ '^0(\\d+)$', '$1' ], //…
在输入金额的UITextField中,要给予三个规则的判断 1. 只能输入数字(可以通过设置键盘类型为Decimal Pad) 2. 小数点只能有一个 3. 小数点后最多有两位数字 (可以通过正则表达式或者长度判断) 2. 和3. 的代码 (首先引入UITextFieldDelegate,指定代理为自己) - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacem…
<input type="text" placeholder="保留到小数点后两位" maxlength="200" onkeyup="num(this)" onpaste="num(this)" /> //输入和黏贴操作时触发 //小数点后两位 function num(obj) { obj.value = obj.value.replace(/[^\d.]/g, "");…
原文地址: http://www.jb51.net/article/45884.htm 四舍五入以下处理结果会四舍五入: ? 1 2 var num =2.446242342; num = num.toFixed(2); // 输出结果为 2.45 不四舍五入以下处理结果不会四舍五入:第一种,先把小数边整数: ? 1 2 Math.floor(15.7784514000 * 100) / 100  // 输出结果为 15.77 第二种,当作字符串,使用正则匹配: ? 1 2 Number(15.…
package com.btzh.mis.house.utils; import java.math.BigDecimal;import java.math.RoundingMode;import java.text.DecimalFormat; /** * Double类型数据处理类 * @author weijixiang * @date 2017/10/17. */public class NumberUtil { public static Double saveOneBit(Doubl…
-(NSString*)getTheCorrectNum:(NSString*)tempString { //计算截取的长度 NSUInteger endLength = tempString.length; //判断字符串是否包含 . if ([tempString containsString:@"."]) { //取得 . 的位置 NSRange pointRange = [tempString rangeOfString:@"."]; NSLog(@&quo…
,),round(UnTaxAmount,))as UnTaxAmount from View_SaleVoice ,)) as UnTaxAmount from View_SaleVoice…
4种方法,都是四舍五入,例: import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; public class format { double f = 111231.5585; public void m1() { BigDecimal bg = new BigDecimal(f); double f1 = bg.setScale(2, BigDecimal.ROUND…
PHP 中的 round() 函数可以实现 round() 函数对浮点数进行四舍五入. round(x,prec) 参数说明x 可选.规定要舍入的数字.prec 可选.规定小数点后的位数. 返回将 x 根据指定精度 prec (十进制小数点后数字的数目)进行四舍五入的结果.prec 也可以是负数或零(默认值). 注释:PHP 默认不能正确处理类似 "12,300.2" 的字符串. 例如:<?phpecho round(-4.635,2);?> 输出: -4.64…
你遇到过页面显示小数有9.987870488E9这个吗? 这是因为没有保留小数的原因 有时候用js保留小数很麻烦的时候,可以用EL表达式 <fmt:formatNumber type="number" value="${member.loginBonusAmount } " maxFractionDigits="2"/> maxFractionDigits:保留几位小数 记住在页面开始需要导入下面的包 <%@ taglib ur…
double percent = Convert.ToDouble(50002.3) / Convert.ToDouble(50002.5) - 0.00005; string result = percent.ToString("p");// 此处,若直接用给定的 50002.3除以 50002.5  得到的 percent 为 0.999996 ,代码会自动四舍五入得到的百分数为 100% 在两数相除的后面加上 -0.00005 后 变会得到99.99% 因为业务需要,被除数如果不…
private Float balance; 代码: <span class="A124_balance_num" th:text="${#numbers.formatDecimal(balance,1,'COMMA',2,'POINT')}"></span> balance=0 输出0.00 balance=325.12 输出325.12 thymeleaf中默认都是调用.toString()方法 转载自:https://blog.csdn…
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <div class="article"> <ul class="clearfix"> <li><span class="price"><c:out value="${bids.period}"…
1. 最笨的办法....... [我就怎么干的.........] function get(){    var s = 22.127456 + "";    var str = s.substring(0,s.indexOf(".") + 3);    alert(str);} 2. 正则表达式效果不错 <script type="text/javascript">onload = function(){    var a = &q…
double d = 23423.24234234d; Response.Write(d.ToString("0.00"));…
最简单使用: float i=1.6667f; string show=i.ToString("0.00"); //结果1.67(四舍五入) 其他类似方法: string show=i.ToString("F");//"F2","f" 不区分大小写 string show=String.Format("{0:F}",i);//也可以为F2,或者"{0:0.00} float j=Math.Roun…
  1.(double) (Math.round(sd3*10000)/10000.0);  这样为保持4位 (double) (Math.round(sd3*100)/100.0); 这样为保持2位. 2.另一种办法 import java.text.DecimalFormat; DecimalFormat df2  = new DecimalFormat("###.00"); DecimalFormat df2  = new DecimalFormat("###.000&…
方案一: import java.text.NumberFormat class CompareHashMap { def regEx_Numeric = '-?[1-9]\\d*$|-?([1-9]\\d*\\.\\d*|0\\.\\d*|0?\\.0+|0)$' def regEx_ScientificNotation = '^((-?\\d+.?\\d*)[Ee]{1}(-?\\d+))$' //科学计数法正则表达式 int decimalPrecision = 5 //Compare 5…
1.用DecimalFormat格式化,DecimalFormat df=new DecimalFormat("0.00"); System.out.println(df.format(1.2)); 追问 如果非得要使用double类型呢? 提问者评............ 2. java中double类型变量保留小数点后两位的问题 mport java.text.*; DecimalFormat df=new DecimalFormat(".##");double…