To round the digits after the decimal point, we can use String.Format() method, here is the example.

为了将小数点后的数字四舍五入,我们可以使用String.Format()方法,这里是示例。

using System;
namespace ConsoleApplication1
{class Program
{static void Main(string[] args)
{//Only two decimal points
Console.WriteLine("Two digits after decimal point");
Console.WriteLine(String.Format("{0:0.00}", 512.4246));
Console.WriteLine(String.Format("{0:0.00}", 512.4));
Console.WriteLine(String.Format("{0:0.00}", 512.0));
Console.WriteLine("\n\nThree digits after decimal point");
Console.WriteLine(String.Format("{0:0.000}", 512.4246));
Console.WriteLine(String.Format("{0:0.000}", 512.4));
Console.WriteLine(String.Format("{0:0.000}", 512.0));
Console.WriteLine();
}
}
}

Output

输出量

Two digits after decimal point
512.42
512.40
512.00
Three digits after decimal point
512.425
512.400
512.000

翻译自: https://www.includehelp.com/dot-net/rounding-digits-after-decimal-point-using-string-format-method.aspx

C#| 使用String.Format()方法将小数点后的数字四舍五入相关推荐

  1. JAVA String.format 方法使用介绍

    在JDK1.5中,String类增加了静态方法format(String format, Objects... args),format(Local l ,String format, Objects ...

  2. JAVA String format 方法使用介绍

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 在JDK ...

  3. String.format()方法详解

    String.format()方法详解 前言: String.format()作为文本处理工具,为我们提供强大而丰富的字符串格式化功能,这里根据查阅的资料做个学习笔记,整理成如下文章,供后续复习查阅. ...

  4. String.format()方法使用说明

    2019独角兽企业重金招聘Python工程师标准>>> JDK1.5开始String类中提供了一个非常有用的方法String.format(String format, Object ...

  5. String.format() 方法用法解说

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. String chargeFlowUrl = _AGENT_URL+ "?agentAcc ...

  6. String.Format()方法

    String.Format方法是我们在.Net应用开发时经常使用到的,它的灵活使用有时能够达到事半功倍的效果,下面我们就借用MSDN上的一个示例来向大家展示String.Format的各种用法. 该示 ...

  7. String.format()方法的使用

    转载自  java字符串格式化:String.format()方法的使用 常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的读者应该记得C ...

  8. C#| 使用String.Format()方法将小数点前的数字四舍五入

    To round the digits before the decimal point, we can use String.Format() method, here is the example ...

  9. Objective-C 字符串拼接函数 多个不同类型的参数拼接到一个字符串 类似于Java中 String.format()方法的原生API

    总目录 iOS开发笔记目录 从一无所知到入门 文章目录 需求 Screenshot Code Output 需求 我有多个参数(类型也许不同),需要拼接到一个字符串中. 在Java中有String.f ...

最新文章

  1. 光模块问题能ping通不能路由_宽带知识小白遇到问题很苦恼?都坐下、不要慌张...
  2. STM32的IIC应用详解3
  3. php如何定义和使用常量,如何在PHP中定义和使用常量
  4. oracle 查询时间跨度一年,关于时间跨度比较的OVERLAPS函数
  5. Linux 运维必备150 个命令,值得收藏!
  6. 有没有code能改xml内容_Spring源码解析-applicationContext.xml加载和bean的注册
  7. _UICreateCGImageFromIOSurface 使用API
  8. bat 修改txt_善用bat命令提高办公效率
  9. [Oracle] 分页查询
  10. 剑指offer58 二叉树的下一个结点
  11. linux系统堆栈内存分配,Linux中堆栈内存在物理上是连续的吗?
  12. 超硬核!小白读了这篇文章,就能在算法圈混了
  13. java调用win32_java调用win32api操作windows窗口
  14. vue实时显示当前时间
  15. wireshark执行XDG问题
  16. IB中文诗歌手法分析
  17. C语言基础——求1加到100的和
  18. sqlmap介绍和用法
  19. JAVA 面试知识点(个人总结)
  20. 微信自主出题,答题小程序开发,微信扫描二维码实现方法,扫二维码出试卷答题的软件!

热门文章

  1. java httpserver 多个接口_多个Servlet之间数据共享实现方案
  2. jenkins修改pom文件_jenkins使用小技巧:pom.xml文件里的版本随着每次发布变化怎么办?...
  3. 在HTML5中如何利用Canvas处理并存储图片
  4. HTML5结合ajax实现文件上传以及进度显示
  5. jquery3和layui冲突导,致使用layui.layer.full弹出全屏iframe窗口时高度152px问题
  6. leetcode 970. 强整数(Powerful Integers)
  7. QT信号和槽函数学习笔记
  8. 40种Javascript中常用的使用小技巧【转】
  9. 找不到显示桌面的快捷方式怎么办|显示桌面的快捷方式找不到解决方法|显示桌面代码|...
  10. C语言 按位或 正整数与负整数 之间