在C#中货币格式,以缩短输出字符串 [英] Currency Format in C# to shorten the output string

查看:207
本文介绍了在C#中货币格式,以缩短输出字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哎,我现在有一个货币格式的方法:

Hey, I currently have a Currency Format method:

private string FormatCurrency(double moneyIn)
{
    CultureInfo ci = new CultureInfo("en-GB");

    return moneyIn.ToString("c", ci);
}



我期待去适应这个缩短的字符串作为货币获得较大的。有点像如何堆栈溢出从999变为而不是1k的1000(或1.6K,而不是1555)。

I'm looking to adapt this to shorten the string as the currency get's larger. Kind of like how stack overflow goes from 999 to 1k instead of 1000 (or 1.6k instead of 1555).

我想,这是一个不过易relativly任务有任建于它的功能或者你只是需要手动操作字符串?

I imagine that this is a relativly easy task however is there any built in function for it or would you just have to manually manipulate the string?

感谢

推荐答案

我会使用以下方法来完成你所需要的东西,我不觉得有什么内建做到这一点直接!

I would use the following to accomplish what you require, I don't think there is anything builtin to do this directly!

return (moneyIn > 999) ? (moneyIn/(double)1000).ToString("c", ci) + "k" : moneyIn.ToString("c", ci);

您可能还需要圆典昶/ 1000〜1 decmial地方的结果。

You may also want to round the result of moneyIn/1000 to 1 decmial place.

心连心

这篇关于在C#中货币格式,以缩短输出字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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