How would I split a number at the decimal and put the two values in separate variables

Examples:  I get a return value of   49.85  I need to put the 49 in var1 and the  .85 in var2.  Ho do  i programmaticly split the values into the two variables?

Thank you
bmanmike39Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
käµfm³d 👽Connect With a Mentor Commented:
double start = 49.85;
double whole = Math.Truncate(start);
double fract = start - whole;

Open in new window

0
 
Element1910Commented:
In your code behind try this (and for example purposes I'll be using a Label (named Label1" that will be displaying your 49.85):
string s = Label1.Text.ToString();
            string[] parts = s.Split('.');
            int var1 = int.Parse(parts[0]);
            int var2 = int.Parse(parts[1]);

Open in new window

0
 
bmanmike39Author Commented:
Thanks it works.
0
All Courses

From novice to tech pro — start learning today.