What is the correct expression to format the decimal 20.3844 as a string with two decimal places?

Study for the MuleSoft Associate / Development Fundamental Test. Master key concepts with flashcards and multiple choice questions, complete with hints and explanations. Prepare thoroughly for your exam!

Multiple Choice

What is the correct expression to format the decimal 20.3844 as a string with two decimal places?

Explanation:
Formatting a number as a string in MuleSoft uses a pattern after the colon where 0 is a required digit and # is optional. To show two decimal places, you want a pattern that guarantees the tenths place and includes the hundredths place if it exists. The pattern ".0#" does that: it prints the tenths digit and then the hundredths digit when present, giving two decimals for a value like 20.3844 (resulting in 20.38 after rounding). The other patterns either force more or fewer decimals or don’t consistently deliver exactly two decimals for this input, so this pattern is the best fit.

Formatting a number as a string in MuleSoft uses a pattern after the colon where 0 is a required digit and # is optional. To show two decimal places, you want a pattern that guarantees the tenths place and includes the hundredths place if it exists. The pattern ".0#" does that: it prints the tenths digit and then the hundredths digit when present, giving two decimals for a value like 20.3844 (resulting in 20.38 after rounding). The other patterns either force more or fewer decimals or don’t consistently deliver exactly two decimals for this input, so this pattern is the best fit.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy