Solved

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

Posted on 2013-01-28
3
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 75

Accepted Solution

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

Open in new window

0
 
LVL 7

Expert Comment

by:Element1910
ID: 38829374
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
ID: 38829481
Thanks it works.
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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