1h Better money round

This commit is contained in:
BuildTools 2016-03-09 17:18:21 +01:00 committed by Olof Larsson
parent aa771c0cbb
commit 5428fa3722
2 changed files with 9 additions and 2 deletions

View File

@ -27,7 +27,7 @@ public abstract class MoneyMixinAbstract implements MoneyMixin
if (fractionalDigits < 0) return amount;
// 0 means no fractional digits
if (fractionalDigits == 0) return Math.ceil(amount);
if (fractionalDigits == 0) return moneyCeil(amount);
// OK! I'll have to calculate :P
int factor = (int) Math.round(Math.pow(10, fractionalDigits));
@ -38,6 +38,12 @@ public abstract class MoneyMixinAbstract implements MoneyMixin
return amount;
}
public static double moneyCeil(double amount)
{
if (amount < 0) return Math.floor(amount);
else return Math.ceil(amount);
}
// -------------------------------------------- //
// MOVE
// -------------------------------------------- //

View File

@ -71,13 +71,14 @@ public class MoneyMixinVault extends MoneyMixinAbstract
else
{
int fractionalDigits = this.fractionalDigits();
amount = prepare(amount);
if (fractionalDigits < 0)
{
return String.valueOf(amount);
}
else if (fractionalDigits == 0)
{
return String.valueOf((int)Math.round(amount));
return String.valueOf((int)amount);
}
else
{