How do I convert string to Indian Money format?(如何将字符串转换为 Indian Money 格式?)
问题描述
我正在尝试将字符串转换为 India Money 格式,例如如果输入为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"
我已经编写了以下代码,但它没有给出预期的输出.
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;
谁能告诉我怎么做?
推荐答案
如果 fare
是 int
, long
, 中的任何一个decimal
, float
或 double
然后我得到预期的输出:
If fare
is any of int
, long
, decimal
, float
or double
then I get the expected output of:
12,34,567.00 卢比
.
我怀疑你的 fare
实际上是一个 string
;字符串不是由 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);
这篇关于如何将字符串转换为 Indian Money 格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将字符串转换为 Indian Money 格式?


基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01