PrepAway - Latest Free Exam Questions & Answers

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?

PrepAway - Latest Free Exam Questions & Answers

A.
Option A

B.
Option B

C.
Option C

D.
Option D

Explanation:
The double keyword signifies a simple type that stores 64-bit floating-point values.
The float keyword signifies a simple type that stores 32-bit floating-point values.

double (C# Reference)

4 Comments on “Which code segment should you use?

  1. Lord Vader says:

    b should also work. shouldnt be a loss of precision however it could be considered not the best choice due to memory constraints
    double is closer to float than decimals




    0



    0
  2. anii says:

    I thought B could also be because:
    Float – 7 digits (32 bit)
    Double – 15-16 digits (64 bit)
    Decimal -28-29 significant digits (128 bit)

    ..but:
    – Decimals and Floats/Doubles cannot be compared without a cast whereas Floats and Doubles can.
    – Decimal is much (much) slower than float and double for most operations, primarily because floating point operations are done in binary, whereas Decimal stuff is done in base 10 (i.e. floats and doubles are handled by the FPU hardware, such as MMX/SSE, whereas decimals are calculated in software).
    – Decimal has an unacceptably smaller value range than double, despite the fact that it supports more digits of precision. Therefore, Decimal can’t be used to represent many scientific values.

    Note: Information is not verified. I found it here: http://stackoverflow.com/questions/618535/difference-between-decimal-float-and-double-in-net




    1



    0

Leave a Reply