Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Problem 495. Formatting currency numbers

Created by Ned Gulley

Given a number, format it properly for textual display using the notation $xxx,xxx,xxx.xx. Assume that no more than two digits will follow the decimal point (i.e. you don't have to worry about rounding). Indicate negative numbers with parentheses.

Examples:

 Input  amt = 34.2
 Output str is '$34.20'
 Input  amt = 91337585
 Output str is '$91,337,585.00'
 Input  amt = -63234922.46
 Output str is '($63,234,922.46)'
 Input  amt = 2784.9
 Output str is '$2,784.90'

Note: Answer this problem in Cody and you'll be helping the person on Answers who asked Function to format number as currency?

Tags

Problem Group

Solution Statistics

32 correct solutions 39 incorrect solutions
Last solution submitted on Sep 26, 2014

Solution Comments