如何将字符串"39.9983%"转换为变成"39%"在C#中? [英] How do I convert the string "39.9983%" into "39%" in C#?
本文介绍了如何将字符串"39.9983%"转换为变成"39%"在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不想向上舍入,"39%"
.
所以"9.99%"
应该变成"9%"
.
推荐答案
string myPercentage = "48.8983%";
string newString = myPercentage.Replace("%","");
int newNumber = (int)Math.Truncate(Double.Parse(newString));
Console.WriteLine(newNumber + "%");
也许有一百种方法可以做到这一点,但这只是一种:)
There maybe hundred ways of doing this and this is just one :)
这篇关于如何将字符串"39.9983%"转换为变成"39%"在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文