d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > I'm So Confused About Certain Datatypes > C#
12Next
Add Reply New Topic New Poll
Member
Posts: 34,587
Joined: Mar 25 2009
Gold: 12,633.00
Aug 14 2015 12:04am
From what i've read, it doesn't really explain things too well


I don't understand float, double, decimal.... and when each should be used.... from my understanding floats are pretty much never used in C# only for extremely large numbers..... and double is used for pretty much everything.... I also heard decimal is used for more precision and used for money a lot....



so say you had a variable with a value of 2.34..... You should use decimal over double? I don't get it.....




all the stuff i've read on this subject is still very ambiguous to me,.... it's very frustrating











EDIT: Would you guys say this is accurate for C# too? if so, that clarifies things a bit, so i'm hoping it's accurate information

http://www.mrexcel.com/forum/microsoft-access/152657-what-does-double-data-type-mean.html

This post was edited by ferf on Aug 14 2015 12:34am
Member
Posts: 34,587
Joined: Mar 25 2009
Gold: 12,633.00
Aug 14 2015 12:31am
also had another question..... say i had a variable with the value of 6

wouldn't it be better to use the datatype "byte" or "sbyte" over "int"?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Aug 14 2015 05:44pm
Quote (ferf @ Aug 14 2015 02:31am)
also had another question..... say i had a variable with the value of 6

wouldn't it be better to use the datatype "byte" or "sbyte" over "int"?


rule of thumbs:
if it's money, use decimal
if it's not money but uses decimal places, use double
if it's an integer value, use int
(personally i use long for ids, but dunno what the standard is for that.)

you almost never wanna use byte, ubyte, short, ushort, uint, etc. dont overanalyze. it's a very small part of programming. use the rule of thumb and move on. focus on other things.

This post was edited by carteblanche on Aug 14 2015 05:45pm
Member
Posts: 34,587
Joined: Mar 25 2009
Gold: 12,633.00
Aug 14 2015 07:07pm
Quote (carteblanche @ Aug 14 2015 07:44pm)
rule of thumbs:
if it's money, use decimal
if it's not money but uses decimal places, use double
if it's an integer value, use int
(personally i use long for ids, but dunno what the standard is for that.)

you almost never wanna use byte, ubyte, short, ushort, uint, etc. dont overanalyze. it's a very small part of programming. use the rule of thumb and move on. focus on other things.


thanks!
Member
Posts: 2,832
Joined: Aug 17 2015
Gold: 1.00
Aug 17 2015 03:09am
regarding the float / double question:

float and double are both used for decimal values, but there is different between these two.

> float got only 6 digits behind the decimal point
> double got 14 or 15 digits (didnt remember if its 14 or 15 digits)

this results in a larger bit value for your numbers, but for console applications it dosnt matter.
thats why you should normaly use double instead of float.

float will be used for some time critical programs / uCs project.
Member
Posts: 34,587
Joined: Mar 25 2009
Gold: 12,633.00
Aug 17 2015 10:14pm
Quote (TragischerEinzelfall @ Aug 17 2015 05:09am)
regarding the float / double question:

float and double are both used for decimal values, but there is different between these two.

> float got only 6 digits behind the decimal point
> double got 14 or 15 digits (didnt remember if its 14 or 15 digits)

this results in a larger bit value for your numbers, but for console applications it dosnt matter.
thats why you should normaly use double instead of float.

float will be used for some time critical programs / uCs project.


ah thanks that clarifies things a lot!
Member
Posts: 29,723
Joined: Jun 11 2007
Gold: 279.52
Sep 16 2015 01:46pm
and the reason you use certain data types is for memory.

you don't want to do something like this

double num = 6;

where u can use an int, as int is only 16 bits and a double is 64 bits, youll be using more memory than needed when assigning variables
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Sep 16 2015 03:22pm
Quote (AkuuZ @ Sep 16 2015 02:46pm)
and the reason you use certain data types is for memory.

you don't want to do something like this

double num = 6;

where u can use an int, as int is only 16 bits and a double is 64 bits, youll be using more memory than needed when assigning variables


Are you trolling? I hope you're trolling.
Member
Posts: 44,911
Joined: Feb 28 2012
Gold: 5.39
Sep 17 2015 11:19am
Quote (Minkomonster @ Sep 16 2015 01:22pm)
Are you trolling? I hope you're trolling.


I think you may be trolling


dafuq?
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Sep 17 2015 04:12pm
Quote (Emp_Mirage @ Sep 17 2015 12:19pm)
I think you may be trolling


dafuq?


Explain?
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll