[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

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
0
bmanmike39
Asked:
bmanmike39
1 Solution
 
käµfm³d 👽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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now