保留两位小数点
- 由于简单的原因大家直接看代码块。
using system; namespace helloworld { class program { static void main(string[] args) { decimal decimals = 34.99999m; double doubles = 34.99999; float floats = 34.99999f; string strings = "34.99999"; console.writeline($"decimal类型的:{decimals:f2}"); console.writeline($"double类型的:{doubles:f2}"); console.writeline($"floats类型的:{floats:f2}"); console.writeline($"string类型的:{strings:f2}");//string类型的不支持这样写。 console.read(); } } }
- 执行结果如下:
黄山市民网:https://www.huangshanshimin.com/