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

推荐订阅源

The Register - Security
The Register - Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MyScale Blog
MyScale Blog
V
Visual Studio Blog
云风的 BLOG
云风的 BLOG
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏
L
LangChain Blog
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security @ Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
人人都是产品经理
人人都是产品经理
H
Hacker News: Front Page
L
Lohrmann on Cybersecurity
T
Troy Hunt's Blog
T
Threat Research - Cisco Blogs
A
About on SuperTechFans
T
Threatpost
AWS News Blog
AWS News Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Tor Project blog
Google Online Security Blog
Google Online Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tenable Blog
W
WeLiveSecurity
博客园 - 叶小钗
K
Kaspersky official blog
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
M
MIT News - Artificial intelligence
Hacker News - Newest:
Hacker News - Newest: "LLM"
Engineering at Meta
Engineering at Meta
有赞技术团队
有赞技术团队
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Secure Thoughts
小众软件
小众软件
D
Docker
爱范儿
爱范儿
C
Cyber Attacks, Cyber Crime and Cyber Security
N
News and Events Feed by Topic
S
Schneier on Security
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net

博客园 - 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就保留几位