【发布时间】:2017-11-23 04:46:31
【问题描述】:
我的浮点数是 100.0,当我将它转换为字符串时它变成了 100。
rmt.MinNumber = 0.0;
rmt.MaxNumber = 100.0;
rmt.MaxLength = rmt.MinNumber.ToString() + " - " + rmt.MaxNumber.ToString();
我知道我能做到
rmt.MinNumber.ToString("0.0");
但这也是保存在 rmt.Decimal 中的设置所以
如果 rmt.Decimal = 1 然后 rmt.MaxLength = 100.0
如果 rmt.Decimal = 2 然后 rmt.MaxLength = 100.00 等等...
如何将其转换为保留其十进制值的字符串
更新
根据 CodeFuller 的建议
public static class Helper
{
public static string Format(this float f, int n)
{
return f.ToString($"0.{new String('0', n)}");
}
}
但目前它给了我错误)预期
【问题讨论】:
标签: c# mysql entity-framework