Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {

allprojects {
group = "com.dumbdogdiner"
version = "3.0.2"
version = "3.0.3"

// java plugin is applied in subprojects
apply plugin: "jacoco"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ private static Boolean validate(CommandSender sender) {
* @param pitch The pitch of the sound
* @param delay T
*/
public static void queueSound(@NotNull Player player, @NotNull Sound sound, @NotNull float volume,
@NotNull float pitch, @NotNull Long delay) {
public static void queueSound(@NotNull Player player, @NotNull Sound sound, float volume, float pitch, long delay) {
StickyAPI.getPool().submit(() -> {
try {
Thread.sleep(delay);
Expand Down Expand Up @@ -100,7 +99,7 @@ public static void sendSuccess(@NotNull Player player) {
* @param type {@link NotificationType} The type of sound
* @return {@link java.lang.Boolean}
*/
public static Boolean send(@NotNull CommandSender sender, @NotNull NotificationType type) {
public static boolean send(@NotNull CommandSender sender, @NotNull NotificationType type) {
if (!validate(sender)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.google.common.primitives.Ints;
import org.jetbrains.annotations.NotNull;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.List;
Expand Down Expand Up @@ -119,10 +121,16 @@ public static <T> T randomElement(@NotNull List<T> list) {
* @return {@link Double}
*/
public static double round(double value, int places) {
long factor = (long) Math.pow(10, places);
value = value * factor;
long tmp = Math.round(value);
return (double) tmp / factor;
return new BigDecimal(value).setScale(places, RoundingMode.HALF_UP).doubleValue();
}

/**
* Rounds a double to 2 decimals
* @param d The double to round
* @return The rounded double
*/
public static double round2Places(double d){
return round(d, 2);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

import org.jetbrains.annotations.NotNull;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Currency;
import java.util.Locale;

/**
* <p>
* Provides extra functionality for Java Number classes.
Expand All @@ -15,6 +23,11 @@ public final class NumberUtil {
private NumberUtil() {
}

private static final NumberFormat moneyFormat = NumberFormat.getCurrencyInstance();
static {
moneyFormat.setCurrency(Currency.getInstance(Locale.US));
}

/**
* <p>
* Checks if the String contains only unicode digits. A decimal point is not a
Expand Down Expand Up @@ -137,4 +150,16 @@ public static int longToInt(@NotNull long lng) {
}
}
}


/**
* Formats a price into US currency format
* @param price Price to format
* @return Formatted String
*/
public static String formatPrice(double price) {
return moneyFormat.format(price);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,15 @@ public void testIntHelperMax() {
public void testIntHelperMin() {
assertEquals(NumberUtil.longToInt(((long) Integer.MIN_VALUE) - 1L), Integer.MIN_VALUE);
}

@Test
public void formatPrice() {
System.out.println(NumberUtil.formatPrice(1.00001));
assertEquals("$1.00", NumberUtil.formatPrice(1.0000001));
}

@Test
public void round2Places() {
assertEquals(6.51D, MathUtil.round2Places(6.509));
}
}