Which code segment should you use?

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

microsoft-exams

3 thoughts on “Which code segment should you use?

  1. 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

    1
    1
  2. It’s B, decimal is more precice than double. decimal was made for financial transaction because it rounds better.

    1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.