我如何用逗号分隔整数(1234,212,123) [英] How I Have To Separate Integer With Commas Like (1234,212,123)

查看:92
本文介绍了我如何用逗号分隔整数(1234,212,123)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jsp页面中,(在struds框架中)我定义了一个html:text字段,field属性是String类型(在bean中定义)。现在,如果我在文本字段中输入整数值,我怎么用逗号分隔这些整数,如(1234,212,123)

解决方案

你需要告诉 ToString 两件事:1)应该使用什么文化来生产某种类型的分隔符,2)指出用于分隔符的内容;它可能是特定文化的默认值。



请参阅:

http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo%28v=vs .110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.numberformat%28v=vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/ system.globalization.cultureinfo%28v = vs.110%29.aspx [ ^ ]。



您还可以定义要使用的文化当前主题:

http:// msdn .microsoft.com / zh-cn / library / system.threading.thread.currentculture.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.threading.thread.currentuiculture.aspx [ ^ ]。



最自定义的方式本文显示了任何具有任意位数的分隔符: http://social.msdn.microsoft.com/Forums/vstudio/en-US/8e1b235f-c10e -49f9-8c4f-13af717944fe / number-format-string-thousand-separator-with-any-number-of-decimal-places?forum = csharpgeneral [ ^ ]。



请参阅:

http://msdn.microsoft.com/en-us/library/dwhawy9k(v = vs.110 ).aspx [ ^ ],

http: //msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx [ ^ ]。



- SA

In a jsp page,(in struds framework) I have defined a html:text field and the field property is String type(defined in bean). Now if I enter the integer value in text field how i have to separate these integer with commas like (1234,212,123)

解决方案

You need to tell ToString two things: 1) what culture should be used to produce certain type of separator, 2) indicate what to use for the separator; it could be the default for the specific culture.

Please see:
http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.numberformat%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo%28v=vs.110%29.aspx[^].

You can also define the culture to use for the current thread:
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentculture.aspx[^],
http://msdn.microsoft.com/en-us/library/system.threading.thread.currentuiculture.aspx[^].

The most customized way of having any separators with any number of digits is shown in this article: http://social.msdn.microsoft.com/Forums/vstudio/en-US/8e1b235f-c10e-49f9-8c4f-13af717944fe/number-format-string-thousands-separator-with-any-number-of-decimal-places?forum=csharpgeneral[^].

Please see:
http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx[^].

—SA


这篇关于我如何用逗号分隔整数(1234,212,123)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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