Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=======================================================================
- // Currency Formatter Plugin (RMMV) v1.1
- //=======================================================================
- // * Converts currency to an alternative, more readable format.
- //
- // © 2015-2016, Companion Wulf
- //-----------------------------------------------------------------------
- // * The Currency Format plugin rewrites the currency into a much more
- // readable format, especially with larger numbers.
- //
- // This plugin was originally inspired by the scriptlet I did for RMVX
- // and RMVXA to split larger currency numbers with commas, thus 100000
- // is shown as 100,000.
- //
- //========================================================================
- // CW_CurrencyFormat.js
- //========================================================================
- var Imported = Imported || {};
- Imported.CW_CurrencyFormatter = true;
- var CWT = CWT || {};
- /*:
- @plugindesc Converts currency to an alternative, more readable format.
- @author Companion Wulf
- @param Currency Format
- @desc Sets the currency format to "Comma" or "Suffix".
- @default Comma
- @help
- Currency Format Plugin v1.0
- © 2016, Companion Wulf
- ========================
- * Options
- ========================
- The plugin has two parameter options:
- "Comma" - Separates numbers with commas, so 100000 becomes 100,000.
- "Suffix" - Replaces trailing zeros with words, i.e. "k" for thousands and "m"
- for millions. Since the maximum allowed value for gold in RMMV is 99,999,999
- this is rounded up to 100,000,000, with the output being "100m". Hence, there
- is no "b" for billions, etc.
- ========================
- * Plugin Commands
- ========================
- This plugin does not provide plugin commands.
- ========================
- * Usage & Copyright
- ========================
- This plugin is free to use under CC BY-SA 4.0, but please refer to the
- RPG Maker Times blogsite for other details and commercial use.
- */
- (function() {
- CWT.parameters = PluginManager.parameters('CW_CurrencyFormatter');
- CWT.currencyFormat = String(CWT.parameters['Currency Format'] || 'Comma');
- CWT.CW_alias_Window_Base_drawCurrencyValue = Window_Base.prototype.drawCurrencyValue;
- Window_Base.prototype.drawCurrencyValue = function(value, unit, x, y, width) {
- var value = this.convertCurrency(value);
- CWT.CW_alias_Window_Base_drawCurrencyValue.call(this, value, unit, x, y, width);
- };
- Window_Base.prototype.convertCurrency = function(value) {
- switch (CWT.currencyFormat.toLowerCase()) {
- case 'comma':
- return value.toLocaleString(); //toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
- break;
- case 'suffix':
- var suffixes = ["", "k", "m"];
- var suffixNumber = Math.floor((""+value).length/3);
- var shortValue = parseFloat((suffixNumber != 0 ? (value / Math.pow(1000,suffixNumber)) : value).toPrecision(2));
- if (shortValue % 1 != 0) shortNumber = shortValue.toFixed(1);
- return shortValue+suffixes[suffixNumber];
- break;
- }
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement