Solved

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

Posted on 2013-01-28
3
251 Views
Last Modified: 2013-01-28
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
Comment
Question by:bmanmike39
3 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
double start = 49.85;
double whole = Math.Truncate(start);
double fract = start - whole;

Open in new window

0
 
LVL 7

Expert Comment

by:Element1910
Comment Utility
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
 

Author Closing Comment

by:bmanmike39
Comment Utility
Thanks it works.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now