473,320 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Compare to double values return Max

How can I compare two double values and return the greater of the two
values?

example
double doublea = 1.0;
double doubleb = 2.0

double retVal = ?compare doublea and doubleb
Nov 16 '05 #1
4 5147
MFRASER wrote:
How can I compare two double values and return the greater of the two
values?
Why not use old-fashioned "if"?
double doublea = 1.0;
double doubleb = 2.0

double retVal = ?compare doublea and doubleb


well, you /could/ do it like this:

\\\
double doublea = 1.0;
double doubleb = 2.0;

double retval = (doublea > doubleb) ? doublea : doubleb;
///

however, I *strongly* recommend use of the "if"-way even if it's more
code to write.

--
Konrad -
http://madrat.net/
Nov 16 '05 #2

"MFRASER" wrote...
How can I compare two double values
and return the greater of the two
values?

example
double doublea = 1.0;
double doubleb = 2.0

double retVal = ?compare doublea and doubleb

double retVal = Math.Max(doublea, doubleb);

or

double retVal = (doublea > doubleb) ? doublea : doubleb;

or

double retVal = 0;
if (doublea > doubleb)
{
retVal = doublea;
}
else
{
retVal = doubleb;
}

// Bjorn A

Nov 16 '05 #3

Thanks for the response I ended up using the Math library.

double retVal = Math.Max(doublea, doubleb)

works very nice.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4


Thanks I ended up using the Math.Max()

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Megan | last post by:
Hi everybody- I'm helping a friend with a music database. She has an old one and is creating a new one. She wants to compare records and fields in the old database with records and fields in the...
5
by: DAVID SCHULMAN | last post by:
I've been trying to perform a calculation that has been running into an underflow (insufficient precision) problem in Microsoft Excel, which calculates using at most 15 significant digits. For this...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
8
by: Kenneth Baltrinic | last post by:
I am trying to compare values coming out of a database record with known default values. The defaults are in an array of type object (because they can be of any basic data type, I am not working...
4
by: aprivate | last post by:
Hi I have a newbie question. I have a value which is of type SINGLE DIM s as single s=3.7
19
by: nickyeng | last post by:
i have a question from my paper, which i dont have the correct answer, so here i asking anyone who can help, provide me the appropriate answer. ----------------------------------- Write a class...
26
by: neha_chhatre | last post by:
can anybody tell me how to compare two float values say for example t and check are two variables declared float how to compare t and check please help me as soon as possible
10
by: agendum97 | last post by:
I have three values: UInt64 a, b, c, d; I need to determine if: (a*b) <=(c*d). Naturally, just doing the multiplication and comparing would tell me the result. However, the values could...
1
by: rockchicx23 | last post by:
i have to develop this snack machine program that makes you chose a snack put money in and give change here is my code so far, what do i use so the program compare the price and money deposited, I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.