You are developing an application that includes methods named ConvertAmount and TransferFunds.
You need to ensure that the precision and range of the value in the amount variable is not lost when the TransferFunds() method is called.
Which code segment should you use?
A. Option A
B. Option B
C. Option C
D. Option D
If it is money, we care precision. So decimal it is.
And from float to double , we dont need a cast .. atleast in 4.7 framework
decimal is wrong because the range is smaller:
Type Approximate range
float ±1.5 x 10−45 to ±3.4 x 1038
decimal ±1.0 x 10-28 to ±7.9228 x 1028
Money should always use decimal……
The answer should be A.
“Why not b?”
This is because: “When you convert float or double to decimal, the source value is converted to decimal representation and rounded to the nearest number after the 28th decimal place if required.”
But by the requirements, you need to ensure that the precision and range of the value in the amount variable is not lost
So what when is rounded? Still precision is way bigger than float and even double.
why not b?