double[] numbers= {1054.32179, -195489100.8377, 1.0437E21,
-1.0573e-05};
string[] specifiers = { "C", "E", "e", "F", "G", "N", "P",
"R", "#,000.000", "0.###E-000",
"000,000,000,000.00###" };
foreach (double number in numbers)
{
Console.WriteLine("Formatting of {0}:", number);
foreach (string specifier in specifiers) {
Console.WriteLine(" {0,-22} {1}",
specifier + ":", number.ToString(specifier));
// Add precision specifiers from 0 to 3.
if (specifier.Length == 1 & ! specifier.Equals("R")) {
for (int precision = 0; precision <= 3; precision++) {
string pSpecifier = String.Format("{0}{1}", specifier, precision);
Console.WriteLine(" {0,-22} {1}",
pSpecifier + ":", number.ToString(pSpecifier));
}
Console.WriteLine();
}
}
Console.WriteLine();
}
// The example displays the following output to the console:
// Formatting of 1054.32179:
// C: $1,054.32
// C0: $1,054
// C1: $1,054.3
// C2: $1,054.32
// C3: $1,054.322
//
// E: 1.054322E+003
// E0: 1E+003
// E1: 1.1E+003
// E2: 1.05E+003
// E3: 1.054E+003
//
// e: 1.054322e+003
// e0: 1e+003
// e1: 1.1e+003
// e2: 1.05e+003
// e3: 1.054e+003
//
// F: 1054.32
// F0: 1054
// F1: 1054.3
// F2: 1054.32
// F3: 1054.322
//
// G: 1054.32179
// G0: 1054.32179
// G1: 1E+03
// G2: 1.1E+03
// G3: 1.05E+03
//
// N: 1,054.32
// N0: 1,054
// N1: 1,054.3
// N2: 1,054.32
// N3: 1,054.322
//
// P: 105,432.18 %
// P0: 105,432 %
// P1: 105,432.2 %
// P2: 105,432.18 %
// P3: 105,432.179 %
//
// R: 1054.32179
// #,000.000: 1,054.322
// 0.###E-000: 1.054E003
// 000,000,000,000.00###: 000,000,001,054.32179
//
// Formatting of -195489100.8377:
// C: ($195,489,100.84)
// C0: ($195,489,101)
// C1: ($195,489,100.8)
// C2: ($195,489,100.84)
// C3: ($195,489,100.838)
//
// E: -1.954891E+008
// E0: -2E+008
// E1: -2.0E+008
// E2: -1.95E+008
// E3: -1.955E+008
//
// e: -1.954891e+008
// e0: -2e+008
// e1: -2.0e+008
// e2: -1.95e+008
// e3: -1.955e+008
//
// F: -195489100.84
// F0: -195489101
// F1: -195489100.8
// F2: -195489100.84
// F3: -195489100.838
//
// G: -195489100.8377
// G0: -195489100.8377
// G1: -2E+08
// G2: -2E+08
// G3: -1.95E+08
//
// N: -195,489,100.84
// N0: -195,489,101
// N1: -195,489,100.8
// N2: -195,489,100.84
// N3: -195,489,100.838
//
// P: -19,548,910,083.77 %
// P0: -19,548,910,084 %
// P1: -19,548,910,083.8 %
// P2: -19,548,910,083.77 %
// P3: -19,548,910,083.770 %
//
// R: -195489100.8377
// #,000.000: -195,489,100.838
// 0.###E-000: -1.955E008
// 000,000,000,000.00###: -000,195,489,100.8377
//
// Formatting of 1.0437E+21:
// C: $1,043,700,000,000,000,000,000.00
// C0: $1,043,700,000,000,000,000,000
// C1: $1,043,700,000,000,000,000,000.0
// C2: $1,043,700,000,000,000,000,000.00
// C3: $1,043,700,000,000,000,000,000.000
//
// E: 1.043700E+021
// E0: 1E+021
// E1: 1.0E+021
// E2: 1.04E+021
// E3: 1.044E+021
//
// e: 1.043700e+021
// e0: 1e+021
// e1: 1.0e+021
// e2: 1.04e+021
// e3: 1.044e+021
//
// F: 1043700000000000000000.00
// F0: 1043700000000000000000
// F1: 1043700000000000000000.0
// F2: 1043700000000000000000.00
// F3: 1043700000000000000000.000
//
// G: 1.0437E+21
// G0: 1.0437E+21
// G1: 1E+21
// G2: 1E+21
// G3: 1.04E+21
//
// N: 1,043,700,000,000,000,000,000.00
// N0: 1,043,700,000,000,000,000,000
// N1: 1,043,700,000,000,000,000,000.0
// N2: 1,043,700,000,000,000,000,000.00
// N3: 1,043,700,000,000,000,000,000.000
//
// P: 104,370,000,000,000,000,000,000.00 %
// P0: 104,370,000,000,000,000,000,000 %
// P1: 104,370,000,000,000,000,000,000.0 %
// P2: 104,370,000,000,000,000,000,000.00 %
// P3: 104,370,000,000,000,000,000,000.000 %
//
// R: 1.0437E+21
// #,000.000: 1,043,700,000,000,000,000,000.000
// 0.###E-000: 1.044E021
// 000,000,000,000.00###: 1,043,700,000,000,000,000,000.00
//
// Formatting of -1.0573E-05:
// C: $0.00
// C0: $0
// C1: $0.0
// C2: $0.00
// C3: $0.000
//
// E: -1.057300E-005
// E0: -1E-005
// E1: -1.1E-005
// E2: -1.06E-005
// E3: -1.057E-005
//
// e: -1.057300e-005
// e0: -1e-005
// e1: -1.1e-005
// e2: -1.06e-005
// e3: -1.057e-005
//
// F: 0.00
// F0: 0
// F1: 0.0
// F2: 0.00
// F3: 0.000
//
// G: -1.0573E-05
// G0: -1.0573E-05
// G1: -1E-05
// G2: -1.1E-05
// G3: -1.06E-05
//
// N: 0.00
// N0: 0
// N1: 0.0
// N2: 0.00
// N3: 0.000
//
// P: 0.00 %
// P0: 0 %
// P1: 0.0 %
// P2: 0.00 %
// P3: -0.001 %
//
// R: -1.0573E-05
// #,000.000: 000.000
// 0.###E-000: -1.057E-005
// 000,000,000,000.00###: -000,000,000,000.00001

C# ToString() 数据格式的更多相关文章

  1. 巧用XML格式数据传入存储过程转成表数据格式

    1.首先将后台数据转成对应的XML数据格式 /// <summary> /// 集合转XML数据格式 /// </summary> /// <param name=&qu ...

  2. easyUI类取嵌套的类型(pastJson结合)

    user类: @Entity@Table(name="c_user")public class User {      @Id @GeneratedValue(strategy=G ...

  3. FinanceJson

    FinanceJson, 对Json的包装.底层使用jackson实现. 1. 生成节点 (1)在某个路径下添加某个节点 FinanceJson financeJsonInfo = FinanceJs ...

  4. whatwg-fetch源码分析

    fetch 是什么 XMLHttpRequest的最新替代技术 fetch优点 接口更简单.简洁,更加语义化 基于promise,更加好的流程化控制,可以不断then把参数传递,外加 async/aw ...

  5. whatwg-fetch

    fetch 是什么 XMLHttpRequest的最新替代技术 fetch优点 接口更简单.简洁,更加语义化 基于promise,更加好的流程化控制,可以不断then把参数传递,外加 async/aw ...

  6. Function.prototype.toString 的使用技巧

    Function.prototype.toString这个原型方法可以帮助你获得函数的源代码, 比如: function hello ( msg ){ console.log("hello& ...

  7. XML和JSON数据格式对比

    概念 XML 扩展标记语言 (Extensible Markup Language, XML) ,用于标记电子文件使其具有结构性的标记语言,可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语 ...

  8. Java将其他数据格式转换成json字符串格式

    package com.wangbo.util; import java.beans.IntrospectionException; import java.beans.Introspector; i ...

  9. MyEclipse开发JAX-RS架构WebServices收发JSON数据格式

    最近因项目需求,开始学习WebServices. 1.开发环境: MyEclipse2013 2.客户端发送的JSON数据格式为 {persons:[{"name":"a ...

随机推荐

  1. 【Redis源代码剖析】 - Redis内置数据结构之压缩字典zipmap

    原创作品,转载请标明:http://blog.csdn.net/Xiejingfa/article/details/51111230 今天为大家带来Redis中zipmap数据结构的分析,该结构定义在 ...

  2. TextView之二:常用属性 分类: H1_ANDROID 2013-10-30 12:43 3203人阅读 评论(0) 收藏

    参考自<疯狂android讲义>2.3节 //TextView所呈现的文字 android:text="我爱Java" //文字颜色 android:textColor ...

  3. [Angular Unit Testing] Testing Pipe

    import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'filesize' }) export class FileSi ...

  4. php 获取提交来源,判断从哪里提交的

    echo $_SERVER['HTTP_REFERER'];这个获取上个页面的url例如获得的是 $url = http://www.weisuyun.com/nihao.html其他页面提交过来的不 ...

  5. JavaScript 正則表達式

    一.简单介绍 1.什么是正則表達式 正則表達式本身就是一种语言,这在其他语言是通用的. 正則表達式(regular expression)描写叙述了一种字符串匹配的模式,能够用来检查一个串是否含有某种 ...

  6. Vert.x ——概述

    Vert.x是什么 Vert.x(http://vertx.io/)是一个基于JVM.轻量级.高性能的应用平台,非常适用于最新的移动端后台.互联网.企业应用架构. Vert.x框架基于事件和异步,依托 ...

  7. Android6.0动态申请权限那些坑--以及避免用户选择不再提示后无法获取权限的问题

    Android 6.0 为了保护用户隐私,将一些权限的申请放在了应用运行的时候去申请, 比如以往的开发中,开发人员只需要将需要的权限在清单文件中配置即可,安装后用户可以在设置中的应用信息中看到:XX应 ...

  8. Warning: file_put_contents(常用单词1.txt): failed to open stream: Invalid argument in

    Warning: file_put_contents(常用单词1.txt): failed to open stream: Invalid argument in 一.总结 1.上述问题是因为Win ...

  9. [TypeScript] Increase TypeScript's type safety with noImplicitAny

    TypeScript tries to infer as much about your code as it can. But sometimes there really is not enoug ...

  10. Log4erl

    http://developerworks.github.io/2011/05/16/erlang-use-log4erl/ Erlang 使用Log4erl all = debug < inf ...