将小数转换为百分比或将小数位数移位。怎么样 [英] Convert decimal to percent or shift decimal places. How

查看:64
本文介绍了将小数转换为百分比或将小数位数移位。怎么样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由2个数字之差生成的,但是它返回的例子是0,07(代表7%)和0.5(代表50%),我只想修复以达到这些目标,例如15,2%13 % 等等。我怎样才能做到这一点? c#是否在CLR上嵌入了某些东西来做到这一点?

I have a that is generated from the diference of 2 numbers, but it return for exemple 0,07 for 7% and 0,5 for 50% i just want to fix to reach these goar, like 15,2% 13% and so on. How can I do that? do c# has something embeded on CLR to do that?

推荐答案

您可以使用百分比自定义数字格式字符串

例如,您可以这样做:

double value = 0.152;
string result = value.ToString("#0.##%");

如果您的语言环境设置为欧洲(我的猜测基于您编写的格式),获得值为 15.2%的字符串。

If your locale is set to European (my guess based off the format you wrote), you'll get a string with the value of "15,2%".

您也可以只使用标准百分比( P)格式化字符串,如果您对默认格式感到满意。

You can also just use the Standard Percentage ("P") Format String, if you're happy with the default formatting.

这篇关于将小数转换为百分比或将小数位数移位。怎么样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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