简体   繁体   English

格式化double - 千位分隔符,带小数但没有尾随零

[英]Format double - thousands separator with decimal but no trailing zeros

I am looking for a format to use with string.Format that would print the following 我正在寻找一种格式与string.Format一起使用,将打印以下内容

double d = 123456.123456D;
double d2 = 123456D;

like 喜欢

123,456.123456
123,456

{0:N6} results in {0:N6}导致

123,456.123456
123,456.000000

{0:0.######} results in {0:0。######}导致

123456.123456
123456

{0:#.0} results in {0:#。0}导致

123,456
123,456

I cannot workout a format that will get me to what I need. 我无法锻炼能够满足我需要的格式。 Will I need to define my own format provider ? 我需要定义自己的格式提供程序吗?

You're close. 你很亲密 Use this format: 使用以下格式:

{0:#,0.######}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 格式编号,带有3个尾随小数位,一个十进制千位分隔符,以及之后的逗号 - format number with 3 trailing decimal places, a decimal thousands separator, and commas after that 格式化小数以删除尾随零并具有千分之一分隔符 - Format a decimal to remove trailing zeros and have a thousandths separator 如何使用前导零和没有分隔符格式化十进制? - How to format decimal with leading zeros and without a separator? 使用逗号格式化十进制,保留尾随零 - Format decimal with commas, preserve trailing zeros 如何格式化没有尾随零的小数 - How to format a decimal without trailing zeros 用千位分隔符解析小数 - Parsing decimal with thousands separator 十进制 - 截断尾随零 - Decimal - truncate trailing zeros 如何将 c# asp-format 标记中的小数格式化为 2 个小数点,如果它是 int,则不带尾随零? - How to format decimal in c# asp-format tag to 2 decimal points and without trailing zeros if it is an int? C#将字符串转换为double / decimal并返回到字符串,保留尾随零,为数千添加coma - C# Convert string to double/decimal and back to string, keeping trailing zeroes, adding comas for thousands 删除尾随零和千位分隔符(逗号) - Remove trailing zeros and thousand separator (comma)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM