zoukankan      html  css  js  c++  java
  • C#double转化成字符串 保留小数位数

    在C#中大家都会遇到这种情况 double类型的数据,需要格式化(保留N未有效数字)或者是保留N为小数等情况,我们往往采取double.tostring("参数");的方法。下面就列出几个常用的方法。

    double temp=3.1415926;

    (F)Fixed point:string str1=temp.toString("f1");//保留一位小数 四舍五入 结果:3.1

    (F)Fixed point:string str2=temp.toString("f2");//保留两位小数,四舍五入 下面一次类推 结果:3.14

    (N)Number:string str2=temp.toString("N");//保留 结果:3.14

    (G)General (default):string str2=temp.toString("G");//保留 结果:3.1415926

    (P)Percent:string str2=temp.toString("P");//保留 结果:314.16%

    (E)Scientific:string str2=temp.toString("E");//保留 结果E:3.141593E+000

    (C)Currency:string str2=temp.toString("C");//保留 结果:¥3.14

  • 相关阅读:
    7、python数据类型之集合set
    python基本数据类型练习
    matplotlib
    numpy常用函数
    pillow包
    keras-tensorflow版本对应
    python-激活和切换运行环境
    端口监控
    numpy
    低风险创业笔记
  • 原文地址:https://www.cnblogs.com/YYi_H/p/2149663.html
Copyright © 2011-2022 走看看