Created
August 26, 2012 20:25
-
-
Save mpjura/3483371 to your computer and use it in GitHub Desktop.
Function that converts numbers to dollar amounts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jshint devel:true */ | |
(function(){ | |
"use strict"; | |
var toDollarAmount = function toDollarAmout(amount, returnAsString){ | |
var ret; | |
if ( 'number' !== typeof amount ){ | |
return false; | |
} | |
ret = amount.toFixed(2); | |
return ( returnAsString ) ? '$' + ret : +ret; | |
}; | |
console.log( toDollarAmount( 5.12341234 ) ); | |
console.log( toDollarAmount( 10, true ) ); | |
console.log( toDollarAmount( 0.129, true ) ); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment