我如何将字符串转换为印度货币格式? [英] How do I convert string to Indian Money format?

查看:263
本文介绍了我如何将字符串转换为印度货币格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想字符串转换为印度货币格式一样,如果输入1234567,那么输出应该为12,34,567

I am trying to convert string to India Money format like if input is "1234567" then output should come as "12,34,567"

我已经写了下面的code,但它没有给预期的输出。

I have written following code but its not giving the expected output.

 CultureInfo hindi = new CultureInfo("hi-IN");
 string text = string.Format(hindi, "{0:c}", fare);
 return text;

谁能告诉我如何做到这一点?

can anyone tell me how to do this?

推荐答案

如果车费任何 INT 中, 小数浮动然后我得到的预期输出:

If fare is any of int, long, decimal, float or double then I get the expected output of:

₹12,34,567.00

我怀疑你的车费实际上是一个字符串;字符串不被的String.Format 格式:他们的的字符串:是没有价值的格式的。所以:首先分析它(使用任何合适的,也许一个不变的十进制解析),然后格式化解析值;例如:

I suspect your fare is actually a string; strings are not formatted by string.Format: they are already a string: there is no value to format. So: parse it first (using whatever is appropriate, maybe an invariant decimal parse), then format the parsed value; for example:

// here we assume that `fare` is actually a `string`
string fare = "1234567";
decimal parsed = decimal.Parse(fare, CultureInfo.InvariantCulture);
CultureInfo hindi = new CultureInfo("hi-IN");
string text = string.Format(hindi, "{0:c}", parsed);


再修改意见;得到公正格式化的值没有货币符号或小数部分:


Edit re comments; to get just the formatted value without the currency symbol or decimal portion:

string text = string.Format(hindi, "{0:#,#}", value);

这篇关于我如何将字符串转换为印度货币格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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