拆分数字 [英] split numeric number
本文介绍了拆分数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,先生,
我想分一个十进制数
例13.23
label1 = 13
label2 = 23
任何人请帮助
提前感谢
解决方案
看看这里: http://msdn.microsoft.com/en-us/library/system.string.split.aspx [ ^ ]并根据您的需要进行操作;)
示例 [ ^ ]
< blockquote>
首先,将它转换为 String
,然后你可以使用 String.Split
拆分字符串的方法:
Dim d As Double = 13 。 23
Dim s 作为 字符串 = Convert.ToString(d)
Dim strArray As String ()= s.Split( 。 C)
Dim beforeDecimalPoint 作为 字符串 = s( 0 )
Dim afterDecimalPoint As String = s( 1 )
如果你想设置 label1的文本
到部分bef得到小数点,并将 label2
的文本设置为小数点后的部分,试试这个:
label1.Text = beforeDecimalPoint
label2.Text = afterDecimalPoint
希望这会有所帮助。
其他解决方案依赖于英文数字格式。您应该使用特定于文化的小数点分隔符:
使用系统;
使用 System.Globalization;
使用 System.Text.RegularExpressions;
正则表达式。拆分(Convert.ToString( 12 。 34 ),Regex.Escape(CultureInfo.CurrentUICulture.NumberFormat.CurrencyDecimalSeparator) ))
Hello sir,
I want to split a decimal number
example 13.23
label1= 13
label2= 23
anyone please help
thanks in advance
解决方案
Have a look here: http://msdn.microsoft.com/en-us/library/system.string.split.aspx[^] and do it to your needs ;)
Example[^]
Hi,
First, convert it to aString
, then you can useString.Split
method to split the string:
Dim d As Double = 13.23 Dim s As String = Convert.ToString(d) Dim strArray As String() = s.Split("."C) Dim beforeDecimalPoint As String = s(0) Dim afterDecimalPoint As String = s(1)
And if you want to set the text oflabel1
to the part before the decimal point, and to set the text oflabel2
to the part after the decimal point, try this:
label1.Text = beforeDecimalPoint label2.Text = afterDecimalPoint
Hope this helps.
Other solutions rely on english numeric format. You should use culture specific decimal separator:
using System; using System.Globalization; using System.Text.RegularExpressions;
Regex.Split(Convert.ToString(12.34), Regex.Escape(CultureInfo.CurrentUICulture.NumberFormat.CurrencyDecimalSeparator))
这篇关于拆分数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文