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

6 thoughts on “Which code segment should you use?

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

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

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

Leave a Reply

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


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