Skip to content

Instantly share code, notes, and snippets.

@mpjura
Created August 26, 2012 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpjura/3483371 to your computer and use it in GitHub Desktop.
Save mpjura/3483371 to your computer and use it in GitHub Desktop.
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