Skip to content

Instantly share code, notes, and snippets.

@mpjura mpjura/to-dollars
Created Aug 26, 2012

Embed
What would you like to do?
Function that converts numbers to dollar amounts
/*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
You can’t perform that action at this time.