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
I think A is still the correct answer in this case. float has a wider range than decimal. In the conversion from float to decimal you could lose digits. If you use double instead, there is no loss of digits.
Check out…
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/float
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/decimal and
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/double
It’s B, decimal is more precice than double. decimal was made for financial transaction because it rounds better.
You are wrong. Accuracy of decimal is excessive for the accuracy of the original float variable “amount” and decimal is very slow because not native processor type.