惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
K
Kaspersky official blog
Forbes - Security
Forbes - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Proofpoint News Feed
G
GRAHAM CLULEY
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Scott Helme
Scott Helme
S
Securelist
美团技术团队
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
W
WeLiveSecurity
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Apple Machine Learning Research
Apple Machine Learning Research
The Cloudflare Blog
AI
AI
L
Lohrmann on Cybersecurity
S
Security Affairs
Cloudbric
Cloudbric
SecWiki News
SecWiki News
爱范儿
爱范儿
雷峰网
雷峰网
Engineering at Meta
Engineering at Meta
C
Cyber Attacks, Cyber Crime and Cyber Security
大猫的无限游戏
大猫的无限游戏
N
News and Events Feed by Topic
I
InfoQ
S
Secure Thoughts
AWS News Blog
AWS News Blog
A
About on SuperTechFans
Schneier on Security
Schneier on Security
酷 壳 – CoolShell
酷 壳 – CoolShell
The Last Watchdog
The Last Watchdog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Check Point Blog
P
Palo Alto Networks Blog
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Google DeepMind News
Google DeepMind News
Latest news
Latest news
I
Intezer
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
V
V2EX
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LangChain Blog
D
Docker

博客园 - refuly

【半原创】将js和css文件装入localStorage加速程序执行 SqlAgent备份脚本 ASP.net 使用HttpHandler实现图片防盗链 提取HTML代码中文字的C#函数 - refuly - 博客园 水晶头的制作 解决ASP.NET“类型初始值设定项引发异常” 解决vs2005 经WebDeployment发布后 global.asax 事件不启动 C# 实现Epson热敏打印机打印 Pos机用 去掉文件名中的非法字符 - refuly - 博客园 window.onbeforeunload与window.onunlad对比 用Response.Filter生成静态页[要注意并发问题] HttpModule通过修改CSS切换皮肤 asp.net Excel导入&导出 - refuly - 博客园 计算机端口的介绍 Sql Server数据导出EXCEL 获取字符串的真实长度 新旧身份证合法性验证及验证算法 C#进制转换 Asp.net 备份、还原Ms SQLServer及压缩Access数据库
c# 小数位数处理
refuly · 2009-04-11 · via 博客园 - refuly

在金额,重量,长度等单位中使用小数是必需的,如只需要保留二位

//默认为保留两位(不进行四舍五入处理)
double  SumPric=0.335333;
string   str1=String.Format( "{0:F} ",SumPric);

//按照四舍五入的国际标准
double  SumPric=0.335333;
Math.Round(0.333333,2);

另外还有一种(这种可以,但是SumPric在我们使用过程中往往是变量,当它为0时,就会出错)
double  SumPric=0.335333;
string   a   =SumPric.ToString( ".## ") ;

______________________________________________________________________________
下面这些我在网上找的,也可以参考下
1.只要求保留N位不四舍5入
float   f   =   0.55555f; 
int   i   =(int)(f   *   100);
f   =   (float)(i*1.0)/100;

2.保留N位,四舍五入     .                
decimal   d=   decimal.Round(decimal.Parse( "0.55555 "),2);

3.保留N位四舍五入
Math.Round(0.55555,2)

4,保留N位四舍五入
double   dbdata   =   0.55555;
string   str1   =     dbdata.ToString( "f2 ");//fN   保留N位,四舍五入

5.保留N位四舍五入
string   result   =   String.Format( "{0:N2} ",   0.55555);//2位
string   result   =   String.Format( "{0:N3} ",   0.55555);//3位

6.保留N位四舍五入
double   s=0.55555;
result=s.ToString( "#0.00 ");//点后面几个0就保留几位