Refine search
/** * Gets GB left. */ public String getGbLeft() { long space = size; space/=1024L; // convert to KB space/=1024L; // convert to MB return new BigDecimal(space).scaleByPowerOfTen(-3).toPlainString(); }
@Override public Double zIncrBy(byte[] key, double increment, byte[] value) { return write(key, DoubleCodec.INSTANCE, RedisCommands.ZINCRBY, key, new BigDecimal(increment).toPlainString(), value); }
@Override public Double zIncrBy(byte[] key, double increment, byte[] value) { return write(key, DoubleCodec.INSTANCE, RedisCommands.ZINCRBY, key, new BigDecimal(increment).toPlainString(), value); }
@Override public Double zIncrBy(byte[] key, double increment, byte[] value) { return write(key, DoubleCodec.INSTANCE, RedisCommands.ZINCRBY, key, new BigDecimal(increment).toPlainString(), value); }
@Override public Double zIncrBy(byte[] key, double increment, byte[] value) { return write(key, DoubleCodec.INSTANCE, RedisCommands.ZINCRBY, key, new BigDecimal(increment).toPlainString(), value); }
@FacesConverter("bigDecimalPlainDisplay") public class BigDecimalDisplayConverter implements Converter { @Override public Object getAsObject(FacesContext context, UIComponent component, String value) { throw new BigDecimal(value); } @Override public String getAsString(FacesContext context, UIComponent component, Object value) { BigDecimal bd = (BigDecimal)value; return bd.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString(); } }
static Double round(Double d, int precise) { BigDecimal bigDecimal = new BigDecimal(d); System.out.println("Before round: " + bigDecimal.toPlainString()); bigDecimal = bigDecimal.setScale(15, RoundingMode.HALF_UP); System.out.println("Hack round: " + bigDecimal.toPlainString()); bigDecimal = bigDecimal.setScale(precise, RoundingMode.HALF_UP); System.out.println("After round: " + bigDecimal.toPlainString()); return bigDecimal.doubleValue(); }
private String millisToSecondsString(long millis) { return new BigDecimal(Long.toString(millis)).divide(new BigDecimal("1000")).toPlainString(); }
private String millisToSecondsString(long millis) { return new BigDecimal(Long.toString(millis)).divide(new BigDecimal("1000")).toPlainString(); }
public static String normalizeNumber(String v) { boolean badBegin = (v.startsWith("0") && v.length() > 1 && v.charAt(1) != '.') // || (v.startsWith("-0") && v.length() > 2 && v.charAt(2) != '.') // || v.startsWith("+"); if (badBegin) { v = new BigDecimal(v).toPlainString(); } while (v.contains(".") && (v.endsWith("0") || v.endsWith("."))) { v = v.substring(0, v.length() - 1); } return v; }
public static String formatFloat0(String value, int n) { if (null != value && value.contains(".")) { if (isNumeric(value)) { try { BigDecimal decimal = new BigDecimal(value); BigDecimal setScale = decimal.setScale(n, BigDecimal.ROUND_HALF_DOWN); return setScale.toPlainString(); } catch (Exception e) { } } } return value; }
public static String formatFloat(String value) { if (null != value && value.contains(".")) { if (isNumeric(value)) { try { BigDecimal decimal = new BigDecimal(value); BigDecimal setScale = decimal.setScale(10, BigDecimal.ROUND_HALF_DOWN).stripTrailingZeros(); return setScale.toPlainString(); } catch (Exception e) { } } } return value; }
import java.math.BigDecimal; import java.text.DecimalFormat; public class Runner { public static void main(String[] args) { double myvalue = 0.00000021d; //Option 1 Print bare double. System.out.println(myvalue); //Option2, use decimalFormat. DecimalFormat df = new DecimalFormat("#"); df.setMaximumFractionDigits(8); System.out.println(df.format(myvalue)); //Option 3, use printf. System.out.printf("%.9f", myvalue); System.out.println(); //Option 4, convert toBigDecimal and ask for toPlainString(). System.out.println(new BigDecimal(myvalue).toPlainString()); System.out.println(); //Option 5, String.format System.out.println(String.format("%.12f", myvalue)); } }
BigDecimal d = new BigDecimal("600.0").setScale(2, RoundingMode.HALF_UP).stripTrailingZeros(); System.out.println(d.toPlainString()); // Printed 600 for me
public static String getFormatSize(double size) { double kiloByte = size / 1024; if (kiloByte < 1) { return "0K"; } double megaByte = kiloByte / 1024; if (megaByte < 1) { BigDecimal result1 = new BigDecimal(Double.toString(kiloByte)); return result1.setScale(2, BigDecimal.ROUND_HALF_UP) .toPlainString() + "KB"; } double gigaByte = megaByte / 1024; if (gigaByte < 1) { BigDecimal result2 = new BigDecimal(Double.toString(megaByte)); return result2.setScale(2, BigDecimal.ROUND_HALF_UP) .toPlainString() + "MB"; } double teraBytes = gigaByte / 1024; if (teraBytes < 1) { BigDecimal result3 = new BigDecimal(Double.toString(gigaByte)); return result3.setScale(2, BigDecimal.ROUND_HALF_UP) .toPlainString() + "GB"; } BigDecimal result4 = new BigDecimal(teraBytes); return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "TB"; }
public static void main (String[] args) throws java.lang.Exception { System.out.println("Rounded: " + round(2.655d,2)); // -> 2.65 System.out.println("Rounded: " + round(1.655d,2)); // -> 1.66 } public static Double round(Double d, int precise) { BigDecimal bigDecimal = new BigDecimal(d); System.out.println("Before round: " + bigDecimal.toPlainString()); bigDecimal = bigDecimal.setScale(precise, RoundingMode.HALF_UP); System.out.println("After round: " + bigDecimal.toPlainString()); return bigDecimal.doubleValue(); }
@Override public RFuture<Integer> addScoreAndGetRankAsync(V object, Number value) { return commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER, "redis.call('zincrby', KEYS[1], ARGV[1], ARGV[2]); " +"return redis.call('zrank', KEYS[1], ARGV[2]); ", Collections.<Object>singletonList(getName()), new BigDecimal(value.toString()).toPlainString(), encode(object)); }
@Override public RFuture<Integer> addScoreAndGetRevRankAsync(V object, Number value) { return commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER, "redis.call('zincrby', KEYS[1], ARGV[1], ARGV[2]); " +"return redis.call('zrevrank', KEYS[1], ARGV[2]); ", Collections.<Object>singletonList(getName()), new BigDecimal(value.toString()).toPlainString(), encode(object)); }
@Override public RFuture<Integer> addScoreAndGetRankAsync(V object, Number value) { return commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER, "redis.call('zincrby', KEYS[1], ARGV[1], ARGV[2]); " +"return redis.call('zrank', KEYS[1], ARGV[2]); ", Collections.<Object>singletonList(getName()), new BigDecimal(value.toString()).toPlainString(), encode(object)); }
@Override public RFuture<Integer> addScoreAndGetRevRankAsync(V object, Number value) { return commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER, "redis.call('zincrby', KEYS[1], ARGV[1], ARGV[2]); " +"return redis.call('zrevrank', KEYS[1], ARGV[2]); ", Collections.<Object>singletonList(getName()), new BigDecimal(value.toString()).toPlainString(), encode(object)); }