将小数,十进制数格式化为两个标签 [英] formatting decimals, decimal number into two label
本文介绍了将小数,十进制数格式化为两个标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我需要在两个不同的标签上显示一个十进制数
例子
45.36
标签1 45
标签2 36
任何人都可以帮助我
提前谢谢大家
解决方案
有很多方法:
这是一个
Sub SplitDecimal( ByVal number As Decimal , ByRef wholePart 作为 十进制, _
ByRef fractionalPart 作为 十进制)
wholePart = Math.Truncate(number)
fractionalPart = number - wholePart
结束 Sub
= OR =
string sample = 235.14587;
string [] output = sample.Split( 。跨度> .ToCharArray());
int before = output [ 0 ]。长度;
int after = output [ 1 ]。长度;
祝你好运,
OI
获取第一部分,您可以执行以下内容:
十进制 .floor( 45 。 36 )
Math.Truncate( 45 。 36 )
to 获取第二部分,
Dim fracPart As Decimal
wholePart = Math.Truncate(number1)
fractPart = number1 - wholePart
< span class =code-comment>' 其中number1将存储45.31
您还可以拆分:
Dim num1 作为 字符串 = 532 。 016 ' 如果这是整数,则转换为字符串
Dim res() As 字符串
res =拆分(num1, 。)
' res(0),res(1)将为您提供单独的值跨度>
Hello everyone,
I need to display a decimal number in two different label
example
45.36
label 1 45
label 2 36
Can anyone help me please
thanks you all in advance
解决方案
Well there are numerous ways:
Here is one
Sub SplitDecimal(ByVal number As Decimal, ByRef wholePart As Decimal, _ ByRef fractionalPart As Decimal) wholePart = Math.Truncate(number) fractionalPart = number - wholePart End Sub
=OR=
string sample = "235.14587"; string[] output = sample.Split(".".ToCharArray()); int before = output[0].Length; int after = output[1].Length;
Good luck,
OI
To get first part, you can do the following: Decimal.floor(45.36) Math.Truncate(45.36) to get second part, Dim fracPart As Decimal wholePart = Math.Truncate(number1) fractPart = number1 - wholePart 'where number1 will store 45.31 you can also split: Dim num1 As String = 532.016 'if this is integer, convert to string Dim res() As String res = Split(num1, ".") 'res(0), res(1) will give you separate values
这篇关于将小数,十进制数格式化为两个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文