43 Replies
I have a question
because there are 3 different decimal points:
float
, double
, and decimal
Which one is the best
to encode a number with 3 digits before the decimal point
and 2 digits after the decimal point
any number between 100.01 and 999.99
with exactly 3 digits before the decimal point and exactly 2 digits after the decimal pointnot one is best. They all have different purposes.
i want the number?
which one will give the correct precision?
float gives about 6 decimal places, double 10, decimal 15
so that 999.99 won't suddenly turn into 1000
based on the example you want decimal
likely
Integer
float is fine with 999.99
is float fine with 999.99 + 0.01 = 1000?
Pope
REPL Result: Success
Console Output
Compile: 442.415ms | Execution: 47.578ms | React with ❌ to remove this embed.
Cattywampus
REPL Result: Success
Console Output
Compile: 387.629ms | Execution: 25.851ms | React with ❌ to remove this embed.
You should state the purpose of this number
It really depends on what you're planning on doing with them.
for counting stuff like money, or amount of something...
If it's money, use decimal.
^
If it's quantity, maybe
double
is fine.but it's for a temporary mantissa without exponent and then the main money would be decimal
If you're going to be doing exponentiation with it,
double
might be the best.is float ok for the mantissa
or is it double?
if it's for money, just use
long
cents.I never used float
but decimal provides you more precise value in c# by using celing and floor software based functions.
but double use binary operations and provide you accurate value in most efficient way.
decimal type is pretty much for money
decimal type is denoted by
m
, which stands for money
fucking Pope typing super quick
I know but I want like a int 12345 (mantissa)
turn into 123.45 times 1000^n
how to store 123.45
or using d would be confusing with double, so m it was
it's not
or
. It is the way it is just how I said.
the etymology isn't of issue here.as a temporary variable
in a method
you have to use Math library functions Floor or Ceil for this purpose
Why do you do this
No datatype will handle this.
why
It's kind of funny that you use the word
mantissa
, but don't think about log10
or similar.Decimal is fine. But why not either just have decimal or handle as integer :catthinking:
Usually I only use the word
mantissa
when talking about the fractional part of an exponent.datatypes are like containers to put a value. It based on you what you put inside. It is not data types duty to perform logic on your value.
and guess what
double
does under the hood for you anywaysCattywampus
REPL Result: Success
Console Output
Compile: 455.555ms | Execution: 50.875ms | React with ❌ to remove this embed.
you don't? you generally don't want to round for money
or else, well.. you'll lose money 🙂
ummm. but he wants to round it to 2 digits only...
truncation or rounding?
those are two different things
I never read about truncation. So, I don't know about it. Let me check what it is.