SHARE
TWEET

Currency Format Plugin (RMMV) v1.1

CompanionWulf Jan 4th, 2016 (edited) 124 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=======================================================================
  2. // Currency Formatter Plugin (RMMV) v1.1
  3. //=======================================================================
  4. //  * Converts currency to an alternative, more readable format.
  5. //
  6. //      © 2015-2016, Companion Wulf
  7. //-----------------------------------------------------------------------
  8. // * The Currency Format plugin  rewrites the currency  into a much more
  9. //   readable format, especially with larger numbers.
  10. //
  11. //   This plugin was originally inspired by the scriptlet I did for RMVX
  12. //   and RMVXA to split larger currency numbers with commas, thus 100000
  13. //   is shown as 100,000.
  14. //
  15. //========================================================================
  16. // CW_CurrencyFormat.js
  17. //========================================================================
  18. var Imported = Imported || {};
  19. Imported.CW_CurrencyFormatter = true;
  20. var CWT = CWT || {};
  21.  
  22. /*:
  23.  @plugindesc Converts currency to an alternative, more readable format.
  24.  @author Companion Wulf
  25.  
  26.  @param Currency Format
  27.  @desc Sets the currency format to "Comma" or "Suffix".
  28.  @default Comma
  29.  
  30.  @help
  31.  Currency Format Plugin v1.0
  32.  © 2016, Companion Wulf
  33.  
  34.  ========================
  35.   * Options
  36.  ========================
  37.   The plugin has two parameter options:
  38.  
  39.   "Comma" - Separates numbers with commas, so 100000 becomes 100,000.
  40.  
  41.   "Suffix" - Replaces trailing zeros with words, i.e. "k" for thousands and "m"
  42.   for millions. Since the maximum allowed value for gold in RMMV is 99,999,999
  43.   this is rounded up to 100,000,000, with the output being "100m". Hence, there
  44.   is no "b" for billions, etc.
  45.  
  46.  ========================
  47.   * Plugin Commands
  48.  ========================
  49.   This plugin does not provide plugin commands.
  50.  
  51.  ========================
  52.   * Usage & Copyright
  53.  ========================
  54.  This plugin is free to use under CC BY-SA 4.0, but please refer to the
  55.  RPG Maker Times blogsite for other details and commercial use.
  56.  
  57. */
  58.  
  59. (function() {
  60.    
  61.     CWT.parameters = PluginManager.parameters('CW_CurrencyFormatter');
  62.     CWT.currencyFormat = String(CWT.parameters['Currency Format'] || 'Comma');
  63.    
  64.     CWT.CW_alias_Window_Base_drawCurrencyValue = Window_Base.prototype.drawCurrencyValue;
  65.     Window_Base.prototype.drawCurrencyValue = function(value, unit, x, y, width) {
  66.         var value = this.convertCurrency(value);
  67.         CWT.CW_alias_Window_Base_drawCurrencyValue.call(this, value, unit, x, y, width);
  68.     };
  69.    
  70.     Window_Base.prototype.convertCurrency = function(value) {
  71.         switch (CWT.currencyFormat.toLowerCase()) {
  72.         case 'comma':
  73.             return value.toLocaleString(); //toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
  74.             break;
  75.         case 'suffix':
  76.             var suffixes = ["", "k", "m"];
  77.             var suffixNumber = Math.floor((""+value).length/3);
  78.             var shortValue = parseFloat((suffixNumber != 0 ? (value / Math.pow(1000,suffixNumber)) : value).toPrecision(2));
  79.             if (shortValue % 1 != 0) shortNumber = shortValue.toFixed(1);
  80.             return shortValue+suffixes[suffixNumber];
  81.             break;
  82.         }
  83.     };
  84.        
  85.  
  86. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top