Click here to Skip to main content
12,885,784 members (37,627 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
Hello everyone,

I need to display a decimal number in two different label



label 1 45
label 2 36

Can anyone help me please

thanks you all in advance
Posted 26-Feb-13 23:57pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

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

Good luck,
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

To get first part, you can do the following:
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
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)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 4 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100