如何根据字符串的十进制值格式化字符串 [英] How to Format a string based on its decimal values

查看:65
本文介绍了如何根据字符串的十进制值格式化字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我得到的数字是分工流程的输出。



我可以,



34

5.03

6.2

123.42



SO格式化字符串后我应该得到两位小数,无论两位小数是否为零我都需要显示零(0)而不是修剪零(0)



所以我的预期输出显示如下



34.00

5.03

6.20

123.42



任何人都可以帮忙摆脱这个问题

Hi,

I am getting a number which is the output of a division process.

I may get,

34
5.03
6.2
123.42

SO After formatting the string I should get two digit decimals not mattering if both decimals are zero I need to display Zero(0) rather than trimming Zero(0)

So My Expected output is shown as follows

34.00
5.03
6.20
123.42

Can anyone help to get rid of this problem

推荐答案

您应该使用 string.Format ,如下例所示:

You should use string.Format like in the next example:
string.Format("{0:#,0.00}", yourNumber);


在System.Math


Use the following function in System.Math

Math.Round(34,2)





以上输出为34.00



The output of above will be 34.00


这篇关于如何根据字符串的十进制值格式化字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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