If I have:
8.24
7.56
1.11
as doubles, how do I easily get just the ".24, .56, .11" ? Thanks,
Yin 6 46370
On 2007-11-20 11:44:43 -0800, Yin99 <ws@ziowave.comsaid:
If I have:
8.24
7.56
1.11
as doubles, how do I easily get just the ".24, .56, .11" ? Thanks,
Well, there's no shortage of methods I'm sure, but the following would work:
double value, fraction;
value = 8.24;
fraction = value - (int) value;
Pete
assuming the number is positive:
double x = myNumber-Math.Floor(myNumber);
"Yin99" <ws@ziowave.comwrote in message
news:84**********************************@b15g2000 hsa.googlegroups.com...
If I have:
8.24
7.56
1.11
as doubles, how do I easily get just the ".24, .56, .11" ? Thanks,
Yin
I have a doubt : what occurs when <doublevalue exceeds <intcapacities ?
Loïc
"Peter Duniho" <Np*********@NnOwSlPiAnMk.coma écrit dans le message de
groupe de discussion : 2007112011594443658-NpOeStPeAdM@NnOwSlPiAnMkcom...
On 2007-11-20 11:44:43 -0800, Yin99 <ws@ziowave.comsaid:
>If I have:
8.24 7.56 1.11
as doubles, how do I easily get just the ".24, .56, .11" ? Thanks,
Well, there's no shortage of methods I'm sure, but the following would
work:
double value, fraction;
value = 8.24;
fraction = value - (int) value;
Pete
On Sun, 30 Dec 2007 01:02:55 -0800, Loïc Berthollet
<lo*************@hotmail.comwrote:
I have a doubt : what occurs when <doublevalue exceeds <int>
capacities ?
Well, using the code you quoted you get an exception, of course.
If you have numbers that aren't within the range of int, you'll have to
use some other method obviously. For example, the Math.Truncate() method
can be used in place of casting to int.
Pete
Loïc Berthollet wrote:
"Peter Duniho" <Np*********@NnOwSlPiAnMk.coma écrit dans le message de
groupe de discussion : 2007112011594443658-NpOeStPeAdM@NnOwSlPiAnMkcom...
>On 2007-11-20 11:44:43 -0800, Yin99 <ws@ziowave.comsaid:
>>If I have:
8.24 7.56 1.11
as doubles, how do I easily get just the ".24, .56, .11" ?
Well, there's no shortage of methods I'm sure, but the following would work:
double value, fraction;
value = 8.24; fraction = value - (int) value;
I have a doubt : what occurs when <doublevalue exceeds <intcapacities ?
You should use:
fraction = value - (long) value;
or nicer:
fraction = value - Math.Floor(value);
to avoid the problem.
Arne
Peter Duniho wrote:
On Sun, 30 Dec 2007 01:02:55 -0800, Loïc Berthollet
<lo*************@hotmail.comwrote:
>I have a doubt : what occurs when <doublevalue exceeds <int> capacities ?
Well, using the code you quoted you get an exception, of course.
Only if compiled with /checked+.
Else the results will become very "weird looking".
If you have numbers that aren't within the range of int, you'll have to
use some other method obviously. For example, the Math.Truncate()
method can be used in place of casting to int.
That is probably better than my suggestion of Math.Floor - most
people will prefer -0.24 instead og 0.76 when applied to -8.24 !
Arne This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Michael Søndergaard |
last post by:
I Pascal there are a function for retriving the fractional part of a real
number (Frac), I can't find any in the dotnet framework. The function needs
to remove the integer part and keep only the...
|
by: Dragon |
last post by:
Helo,
There're so many methods for rounding in .NET, but I can't find any that
will just drop fractional part of a number, e.g: -3.9 => -3.
I tried:
CInt(-3.9)
Int(-3.9)
Math.Round(-3.9)
|
by: djzbor |
last post by:
Any who can help!!
let i have a number 16.0230045
i want to count the fractional part of this number means i want to get the number of digits of the fractional part of this number and store each...
|
by: Bob |
last post by:
Greetings All,
Is there a simple way of suppressing the fractional part of a timespan
At the moment I use one time span to populate another minus the fractional
part .. this is a bit clunky.
...
|
by: Evyn |
last post by:
Hi all,
I have recently asked for advice:
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/1b42e6855a2c571b/e63d8f10b51f015c?lnk=raot#e63d8f10b51f015c
My task is to convert a...
|
by: bsabiston |
last post by:
Hi, I'm trying to get the fractional part of a floating point
number. I've tried fmod() and modf(), and while both do work, they
also occasionally return 1.0 for the fractional part of the number...
|
by: Chris Rebert |
last post by:
On Wed, Nov 19, 2008 at 10:01 PM, srinivasan srinivas
<sri_annauni@yahoo.co.inwrote:
Since you really care about significant figures here, have you
considered using decimal rather than float as,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |