Click here to Skip to main content
15,885,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

Well there are numerous ways:
Here is one
VB
Sub SplitDecimal(ByVal number As Decimal, ByRef wholePart As Decimal, _
                 ByRef fractionalPart As Decimal)
    wholePart = Math.Truncate(number)
    fractionalPart = number - wholePart
End Sub


=OR=
VB
string sample = "235.14587";
string[] output = sample.Split(".".ToCharArray());
int before = output[0].Length;
int after = output[1].Length;


Good luck,
OI
 
Share this answer
 
v2
VB
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
 
Share this answer
 
Comments
Orcun Iyigun 27-Feb-13 6:22am    
Well how is your solution different than mine?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900