473,320 Members | 2,112 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.

Number

Hello,

What should be the data type for holding numbers with 2 decimal places
(2.32, 4.23, 1.23, ...)?

Thanks,
Miguel

Mar 23 '07 #1
10 1218
"shapper" <md*****@gmail.comwrote in message
news:11**********************@d57g2000hsg.googlegr oups.com...
What should be the data type for holding numbers with 2 decimal places
(2.32, 4.23, 1.23, ...)?
Well, in terms of numbers of bytes, the smallest floating-point datatype is
float, which uses 32 bytes...
http://msdn2.microsoft.com/en-us/library/9ahet949.aspx
Mar 23 '07 #2
On 23 Mar 2007 10:42:07 -0700, shapper wrote:
Hello,

What should be the data type for holding numbers with 2 decimal places
(2.32, 4.23, 1.23, ...)?

Thanks,
Miguel
Personally I would use decimal over float

--
Bits.Bytes
http://bytes.thinkersroom.com
Mar 23 '07 #3
"Rad [Visual C# MVP]" <no****@nospam.comwrote in message
news:19****************@thinkersroom.com...
Personally I would use decimal over float
Why?
Mar 23 '07 #4
precision.

a float is in 2 complement, not decimal, so 1/10, is not really .01, and
can cause errors in summations.

decimal is really done as an integer value with an implied decimal
point, so .01 is really .01
-- bruce (sqlwork.com)
Mark Rae wrote:
"Rad [Visual C# MVP]" <no****@nospam.comwrote in message
news:19****************@thinkersroom.com...
>Personally I would use decimal over float

Why?

Mar 23 '07 #5
"bruce barker" <no****@nospam.comwrote in message
news:Oh**************@TK2MSFTNGP04.phx.gbl...
precision.

a float is in 2 complement, not decimal, so 1/10, is not really .01, and
can cause errors in summations.

decimal is really done as an integer value with an implied decimal point,
so .01 is really .01
Sure, but the OP is looking for the most efficient way of storing numbers
with two decimal places... A float is fine for that, and will require only
32 bits as opposed to the 128 bits required by a decimal...
Mar 23 '07 #6
Mark Rae wrote:
"shapper" <md*****@gmail.comwrote in message
news:11**********************@d57g2000hsg.googlegr oups.com...
>What should be the data type for holding numbers with 2 decimal places
(2.32, 4.23, 1.23, ...)?

Well, in terms of numbers of bytes, the smallest floating-point datatype is
float, which uses 32 bytes...
http://msdn2.microsoft.com/en-us/library/9ahet949.aspx
32 bits, not 32 bytes. :)

--
Göran Andersson
_____
http://www.guffa.com
Mar 24 '07 #7
shapper wrote:
Hello,

What should be the data type for holding numbers with 2 decimal places
(2.32, 4.23, 1.23, ...)?

Thanks,
Miguel
That depends on what you are going to use them for.

Double is the most common data type for floating point numbers, and
generally gives the best performance.

If you have a lot of numbers, you can use Single. As it's smaller you
get better performance, as there is less data to move around.

If you need absolute precision, you can use Decimal. It's larger, but it
doesn't approximate the values as Single and Double does.

Another way yo get absolute precision is to represent the values as
integer values multiplied by hundred. An Int is good for nine digits. A
Short only manages four digits, but it's even smaller than a Singe, so
you can use that if you really need to save memory.

--
Göran Andersson
_____
http://www.guffa.com
Mar 24 '07 #8
"Göran Andersson" <gu***@guffa.comwrote in message
news:ek**************@TK2MSFTNGP06.phx.gbl...
>Well, in terms of numbers of bytes, the smallest floating-point datatype
is float, which uses 32 bytes...
http://msdn2.microsoft.com/en-us/library/9ahet949.aspx

32 bits, not 32 bytes. :)
Yes I know - it was late... :-(
Mar 24 '07 #9
"Göran Andersson" <gu***@guffa.comwrote in message
news:OZ**************@TK2MSFTNGP03.phx.gbl...
Short only manages four digits, but it's even smaller than a Singe
A Single, not a Singe (unless, of course, you are talking about French
monkeys...)

:-)
Mar 24 '07 #10
Mark Rae wrote:
"Göran Andersson" <gu***@guffa.comwrote in message
news:OZ**************@TK2MSFTNGP03.phx.gbl...
>Short only manages four digits, but it's even smaller than a Singe

A Single, not a Singe (unless, of course, you are talking about French
monkeys...)

:-)
Of course not. I was talking about a superficial burn injury. ;)

--
Göran Andersson
_____
http://www.guffa.com
Mar 24 '07 #11

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

Similar topics

3
by: Shay Hurley | last post by:
this is probably a stupid question so apologies in advance. I am trying to format a number to look like a phone number with "-"'s between the numbers etc e.g. 15554256987 should be formatted as...
8
by: EAS | last post by:
Hey, I'm new to python (and programming in general) so I'll prolly be around here a lot... Anyways, I've found out how to make a "guess my number game" where the player guesses a number between...
11
by: don | last post by:
Ok, this is a homework assignment, but can you help me out anyway...... I need a routine for figuring out if a number inputted by the user is a prime number or not...... all I'm asking for is Not...
27
by: Gaijinco | last post by:
Sooner or later everytime I found recreational programming challenges I stumble with how I test if a number is has decimal places differnt than 0? For example if I want to know if a number is a...
13
by: Ron | last post by:
Hi all I'm deciding whether to use the PK also as an account number, invoice number, transaction number, etc that the user will see for the respective files. I understand that sometimes a...
19
by: gk245 | last post by:
Trying to write a program that will figure out if a number is perfect or not. Here is my logic: 1) Read in the number 2) Split it up (number - 1) 3) Put all the split up numbers into an...
4
by: SweetLeftFoot | last post by:
Hello, i have designed some code that works out the first 250 prime numbers and prints them to the screen. However i need to implement 2 functions, one of which returns a 1 if the number is a prime...
4
by: fatimahtaher | last post by:
Hi, I am supposed to create a program that generates a random number and then asks the user to guess the number (1-100). The program tells the user if he guessed too high or too low. If he...
5
by: silversnake | last post by:
I'm trying to write a program that take a input number and prints if is a prime numbers but is not working for instance, it says that 4 is prime while 5 is not. can anyone see what the problem is ....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
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: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.