Click here to Skip to main content
15,903,724 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
Hello sir,

I want to split a decimal number

example 13.23

label1= 13
label2= 23

anyone please help

thanks in advance
Posted
Comments
Sergey Alexandrovich Kryukov 4-Mar-13 14:46pm    
Please stop posting non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership.
Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
—SA

Have a look here: http://msdn.microsoft.com/en-us/library/system.string.split.aspx[^] and do it to your needs ;)

Example[^]
 
Share this answer
 
v2
Comments
Thomas Daniels 4-Mar-13 13:39pm    
I agree, +5!
Maciej Los 4-Mar-13 14:07pm    
Thank you!
Hi,

First, convert it to a String, then you can use String.Split method to split the string:
VB
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 of label1 to the part before the decimal point, and to set the text of label2 to the part after the decimal point, try this:
VB
label1.Text = beforeDecimalPoint
label2.Text = afterDecimalPoint

Hope this helps.
 
Share this answer
 
v2
Comments
Maciej Los 4-Mar-13 13:38pm    
+5!
Thomas Daniels 4-Mar-13 13:39pm    
Thank you!
[no name] 4-Mar-13 14:57pm    
Should not strArray be declared as String()?
Thomas Daniels 5-Mar-13 13:01pm    
Thank you! I updated it!
Other solutions rely on english numeric format. You should use culture specific decimal separator:
C#
using System;
using System.Globalization;
using System.Text.RegularExpressions;

C#
Regex.Split(Convert.ToString(12.34), Regex.Escape(CultureInfo.CurrentUICulture.NumberFormat.CurrencyDecimalSeparator))
 
Share this answer
 
v2

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