至少使用2位和最多6位格式化小数 [英] Format a decimal using at least 2 places and at most 6 places

查看:92
本文介绍了至少使用2位和最多6位格式化小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要满足规范,我需要使用以下规则设置十进制值的格式:

To meet a specification I need to format a decimal value with the rule:


  • 所有值必须至少包含两个小数点后最多6位。

  • All values must have at least two decimal places and at most six.

例如:

Value        Formatted
1            1.00
1.1          1.10
1.1234       1.1234
1.123456     1.123456
1.12345678   1.123456

我想我将使用条件结束,但是我想知道是否有格式字符串可以做到这一点。

I guess I'll end using a condition, but I wonder if there is a format string which can do this.

推荐答案

您是否尝试过:

.ToString( 0.00 ####);

这篇关于至少使用2位和最多6位格式化小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆