Add support for Metric prefixes to display large numbers

Indications are used as defined on:
http://en.wikipedia.org/wiki/Metric_prefix, implemented from 'k' to 'Y'.
Added setting 'metricSuffixesAbove' to config.yml to specify from which
number these characters should be used.
Added setting 'decimalMark' to change the character(s) used as decimal
separation (is a comma instead of a dot in certain countries).
This commit is contained in:
Thijs Wiefferink 2015-05-03 00:15:05 +02:00
parent c92bc716dc
commit 791b696aff
2 changed files with 64 additions and 18 deletions

View File

@ -579,17 +579,52 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
before = before.replace(currencyEuro, "\u20ac");
String after = this.getConfig().getString("moneyCharacterAfter");
after = after.replace(currencyEuro, "\u20ac");
BigDecimal bigDecimal = new BigDecimal(amount);
bigDecimal = bigDecimal.setScale(getConfig().getInt("fractionalNumbers"), RoundingMode.HALF_UP);
if(bigDecimal.doubleValue() > 1000000000) {
bigDecimal = bigDecimal.stripTrailingZeros();
}
double newAmount = bigDecimal.doubleValue();
if(getConfig().getBoolean("hideEmptyFractionalPart") && (newAmount%1.0) == 0.0) {
return before + bigDecimal.toString().replace(".0", "") + after;
String result;
// Add metric
double metricAbove = getConfig().getDouble("metricSuffixesAbove");
if(metricAbove != -1 && amount >= metricAbove) {
if(amount >= 1000000000000000000000000.0) {
amount = amount/1000000000000000000000000.0;
after = "Y" + after;
} else if(amount >= 1000000000000000000000.0) {
amount = amount/1000000000000000000000.0;
after = "Z" + after;
} else if(amount >= 1000000000000000000.0) {
amount = amount/1000000000000000000.0;
after = "E" + after;
} else if(amount >= 1000000000000000.0) {
amount = amount/1000000000000000.0;
after = "P" + after;
} else if(amount >= 1000000000000.0) {
amount = amount/1000000000000.0;
after = "T" + after;
} else if(amount >= 1000000000.0) {
amount = amount/1000000000.0;
after = "G" + after;
} else if(amount >= 1000000.0) {
amount = amount/1000000.0;
after = "M" + after;
} else if(amount >= 1000.0) {
amount = amount/1000.0;
after = "k" + after;
}
BigDecimal bigDecimal = new BigDecimal(amount);
bigDecimal.setScale(getConfig().getInt("fractionalNumbers"), RoundingMode.HALF_UP);
if(bigDecimal.toString().contains(".")) {
int frontLength = bigDecimal.toString().substring(0, bigDecimal.toString().indexOf('.')).length();
bigDecimal = bigDecimal.setScale(getConfig().getInt("fractionalNumbers") + (3-frontLength), RoundingMode.HALF_UP);
}
result = bigDecimal.toString();
} else {
return before + bigDecimal.toString() + after;
BigDecimal bigDecimal = new BigDecimal(amount);
bigDecimal.setScale(getConfig().getInt("fractionalNumbers"), RoundingMode.HALF_UP);
result = bigDecimal.toString();
if(getConfig().getBoolean("hideEmptyFractionalPart") && (amount%1.0) == 0.0 && result.contains(".")) {
result = result.substring(0, result.indexOf('.'));
}
}
result = result.replace(".", getConfig().getString("decimalMark"));
return before + result + after;
}
/**

View File

@ -7,14 +7,6 @@
# └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
## Chatprefix used for all messages in the chat, also changes the greeting messages.
chatPrefix: '&2[AreaShop]&r '
## The characters used for the prices of regions, will appear before the number, for the euro character use '%euro%'
moneyCharacter: '$'
## The characters used after a currency number, '%euro%' will become the euro character
moneyCharacterAfter: ''
## How many numbers behind the dot should be shown (2 will make numbers like '8.55', '9.01')
fractionalNumbers: 2
## Set this to true if you want to hide '.0' for a number like '15.0' ('4.50' will still stay '4.50')
hideEmptyFractionalPart: true
## The language file that should be used, check the 'lang' folder for build-in languages (use the filename without .yml here)
language: EN
## The tags you need to write on the sign to trigger the plugin
@ -33,7 +25,8 @@ signTags:
## This means it would also block 'house_123' and 'house_000456'. It will not block 'ahouse_1' or 'house_'.
blacklist:
- '__global__'
## Enable sending stats to http://mcstats.org/ (Metrics plugin)
## Enable sending stats to http://mcstats.org/ (Metrics plugin).
## This information will give me an indication about how much the plugin is used and encourages me to continue development.
sendStats: true
## If enabled it will check for updates when loading the plugin, it will never download files, it will only notify about it
## A message will be printed in the console when an update is available and OPs will be notified when joining the server
@ -51,6 +44,24 @@ debug: false
version: ${project.version}
# ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
# │ NUMBERS: Options to change the output of prices │
# └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
## The characters displayed before a price, special characters like € can be used
moneyCharacter: '$'
## The characters displayed after a price, special characters like € can be used
moneyCharacterAfter: ''
## How many numbers behind the dot should be shown (2 will make numbers like '8.55', '9.01')
fractionalNumbers: 2
## Set this to true if you want to hide '.0' for a number like '15.0' ('4.50' will still stay '4.50')
hideEmptyFractionalPart: true
## Use metric suffixes if the price is above this number (use 1.00M instead of 1000000.00 etc.), use -1 for disable
## Indications are used as defined on: http://en.wikipedia.org/wiki/Metric_prefix, implemented from 'k' to 'Y'
metricSuffixesAbove: 1000000.0
## The character(s) to use as decimal mark
decimalMark: '.'
# ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
# │ RENTING: Options that apply to all rent regions │
# └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘