C#中如何只保留小数点后面两位?
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.3333333"),2)
5、
private System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo(); float test=0.333333f;
nfi.NumberDecimalDigits=2;
string result=test.ToString("N", nfi);
6、
string result= String.Format("{0:N2}",Convert.ToDecimal("0.333333").ToString());
C#中如何只保留小数点后面两位?的更多相关文章
- 关于Oracle中查询的数字值的显示格式需要保留小数点后两位(或者三位,及其他位数)
关于Oracle中查询的数字值的显示格式需要保留小数点后两位(或者三位,及其... 方法一:使用to_char的fm格式,即: to_char(round(data.amount,2),'FM9999 ...
- mysql格式化小数保留小数点后两位(小数点格式化)
格式化浮点数的问题,用format(col,2)保留两位小数点,出现一个问题,例如下面的语句,后面我们给出解决方法 SELECT FORMAT(12562.6655,2); 结果:12,562.67 ...
- js使用“toFixed( )”保留小数点后两位
例如: var a = 1.335; alert(a.toFixed(2)) // IE 1.34 //chorme 1.33 若a为字符串,则需要先转换为Number类型 如: n = Number ...
- input内强制保留小数点后两位 位数不足时自动补0
input内强制保留小数点后两位 位数不足时自动补0 小数点后位数超出2位时进行四舍五入 需引入jquery包 1.11.2版本 1 function xiaoshu(x) 2 { 3 var f = ...
- JAVA除法保留小数点后两位的两种方法 Java Math的 floor,round和ceil的总结
floor 返回不大于的最大整数 round 则是4舍5入的计算,入的时候是到大于它的整数round方法,它表示“四舍五入”,算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下 ...
- input输入框只能输入正数和小数(保留小数点后两位)
1.限制只能输入正数和小数保留小数点后两位 1 <input type="number" id="txtNum" /> 2 3 <script ...
- input只能输入数字和小数点,并且只能保留小数点后两位 - CSDN博客
1.给文本框添加一个onkeyup=’clearNoNum(this)’点击事件 2.建立clearNoNum方法 function clearNoNum(obj) { obj.value = obj ...
- Oracle保留小数点后两位的几种方法
有时候在做数据处理的时候,在前台页面上显示的数字需要保留小数点的后两位,不足两位的用0代替,这个时候就需要对数据做一些处理了.如果只用round(value,2)(四舍五入)和trunc(value, ...
- js控制input框只能输入数字和一位小数点和小数点后面两位小数
<script language="JavaScript" type="text/javascript"> function clearNoNum( ...
随机推荐
- Sort(归并)
Sort 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 You want to processe a sequence of n distinct integers ...
- JSTL 格式化输出 Calendar
今天遇到一个jstl在页面输出Calendar对象的问题,网上各种百度都说不能直接格式化,但是经过自己的尝试,原来是可以直接格式化的. 做个备忘吧. 对象的createTime字段类型是Calenda ...
- [CSS3] CSS Display Property: Block, Inline-Block, and Inline
Understanding the most common CSS display types of block, inline-block, and inline will allow you to ...
- [RxJS] Using Observable.create for fine-grained control
Sometimes, the helper methods that RxJS ships with such as fromEvent, fromPromise etc don't always p ...
- uva 230 Borrowers(摘)<vector>"结构体“ 膜拜!
I mean your borrowers of books--those mutilators of collections, spoilers of the symmetry of shelves ...
- MySQL数据库SQL层级优化
本篇主涉及MySQL SQL Statements层面的优化. 首先,推荐一个链接为万物之始:http://dev.mysql.com/doc/refman/5.0/en/optimization.h ...
- js 原型
1: function Person (name,age) { 2: this.name = name; 3: this.age = age; 4: } 5: 6: Person.prototyp ...
- Python学习笔记四,dict和set
dict是字典dictionary的缩写,他存放的是键值对key/value,用花括号表示,格式为d={'micheal':99,'jack':88} 当我们访问的时候直接print(d['miche ...
- python 连接Mysql数据库
1.下载http://dev.mysql.com/downloads/connector/python/ 由于Python安装的是3.4,所以需要下载下面的mysql-connector-python ...
- abiword Namespace List
abiword Namespace List Here is a list of all namespaces with brief descriptions: abicollab 这个命名空间以及 ...