Example usage for java.math BigDecimal longValue

List of usage examples for java.math BigDecimal longValue

Introduction

In this page you can find the example usage for java.math BigDecimal longValue.

Prototype

@Override
public long longValue() 

Source Link

Document

Converts this BigDecimal to a long .

Usage

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("123.67");
    BigDecimal bg2 = new BigDecimal("1234567890987654");

    // assign the long value of bg1 and bg2 to l1,l2 respectively
    long l1 = bg1.longValue();
    long l2 = bg2.longValue();

    System.out.println(l1);/*w w  w  .  ja  v  a  2  s  .c  o  m*/
    System.out.println(l2);
}

From source file:Main.java

public static long decimalToInteger(BigDecimal value) {
    return value.longValue();
}

From source file:Main.java

public static long convertsToLong(double v) {
    BigDecimal b = new BigDecimal(v);
    return b.longValue();
}

From source file:Main.java

public static String setThousandSeparator(long number) {
    BigDecimal bd = new BigDecimal(number);
    NumberFormat formatter = NumberFormat.getInstance();
    return formatter.format(bd.longValue());
}

From source file:com.legstar.mock.client.MockLsfileaq.java

/**
 * Get the max number of replies from a host byte array.
 * @param hostData the host byte array/*from   w w w. j av a  2s. c  o m*/
 * @return the max number of items
 */
private static long getMaxReplies(final byte[] hostData) {
    try {
        BigDecimal bigD = CobolBinarySimpleConverter.fromHostSingle(2, true, 4, 0, hostData, 0);
        return bigD.longValue();
    } catch (CobolConversionException e) {
        e.printStackTrace();
        return 0L;
    }
}

From source file:fr.univrouen.poste.domain.PosteCandidatureFile.java

public static Long getSumFileSize() {
    String sql = "SELECT SUM(file_size) FROM poste_candidature_file";
    Query q = entityManager().createNativeQuery(sql);
    BigDecimal bigValue = (BigDecimal) q.getSingleResult();
    if (bigValue != null) {
        return bigValue.longValue();
    } else {//from  w w  w.  j av a  2 s.  co  m
        return new Long(0);
    }
}

From source file:fr.univrouen.poste.domain.PosteCandidatureFile.java

public static Long getSumNbPages() {
    String sql = "SELECT SUM(nb_pages) FROM poste_candidature_file";
    Query q = entityManager().createNativeQuery(sql);
    BigDecimal bigValue = (BigDecimal) q.getSingleResult();
    if (bigValue != null) {
        return bigValue.longValue();
    } else {//from w w w.  j  av a 2 s . c  o  m
        return new Long(0);
    }
}

From source file:com.legstar.mock.client.MockLsfileac.java

/**
 * Get the max number of items from a host byte array.
 * //  w  ww .ja va2  s.  c o  m
 * @param hostData the host byte array
 * @return the max number of items
 */
private static long getMaxItems(final byte[] hostData) {
    try {
        BigDecimal bigD = CobolPackedDecimalSimpleConverter.fromHostSingle(5, 8, 0, hostData, 0);
        return bigD.longValue();
    } catch (CobolConversionException e) {
        e.printStackTrace();
        return 0L;
    }
}

From source file:nu.mine.kino.projects.utils.Utils.java

static Date excelSerialValue2Date(String serial) {
    BigDecimal dec = new BigDecimal(serial).subtract(new BigDecimal("25569")).subtract(new BigDecimal("0.375"));
    BigDecimal ans = dec.multiply(new BigDecimal("86400000"));
    return new Date(ans.longValue());
}

From source file:io.github.benas.jpopulator.impl.BeanValidationRandomizer.java

/**
 * Generate a random value according to the validation constraint present on a field.
 *
 * @param field the field to populate/*from w  w  w. j a  v  a  2 s  .  c  o m*/
 * @return a random value according to the validation constraint
 */
public static Object getRandomValue(final Field field) {

    Class<?> fieldType = field.getType();

    Object result = null;

    if (field.isAnnotationPresent(AssertFalse.class)) {
        result = false;
    }
    if (field.isAnnotationPresent(AssertTrue.class)) {
        result = true;
    }
    if (field.isAnnotationPresent(Null.class)) {
        result = null;
    }
    if (field.isAnnotationPresent(Future.class)) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.YEAR, ConstantsUtil.DEFAULT_DATE_RANGE);
        result = new DateRangeRandomizer(new Date(), calendar.getTime()).getRandomValue();
    }
    if (field.isAnnotationPresent(Past.class)) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.YEAR, -ConstantsUtil.DEFAULT_DATE_RANGE);
        result = new DateRangeRandomizer(calendar.getTime(), new Date()).getRandomValue();
    }
    if (field.isAnnotationPresent(Max.class)) {
        Max maxAnnotation = field.getAnnotation(Max.class);
        long maxValue = maxAnnotation.value();
        result = MaxValueRandomizer.getRandomValue(fieldType, maxValue);
    }
    if (field.isAnnotationPresent(DecimalMax.class)) {
        DecimalMax decimalMaxAnnotation = field.getAnnotation(DecimalMax.class);
        BigDecimal decimalMaxValue = new BigDecimal(decimalMaxAnnotation.value());
        result = MaxValueRandomizer.getRandomValue(fieldType, decimalMaxValue.longValue());
    }
    if (field.isAnnotationPresent(Min.class)) {
        Min minAnnotation = field.getAnnotation(Min.class);
        long minValue = minAnnotation.value();
        result = MinValueRandomizer.getRandomValue(fieldType, minValue);
    }
    if (field.isAnnotationPresent(DecimalMin.class)) {
        DecimalMin decimalMinAnnotation = field.getAnnotation(DecimalMin.class);
        BigDecimal decimalMinValue = new BigDecimal(decimalMinAnnotation.value());
        result = MinValueRandomizer.getRandomValue(fieldType, decimalMinValue.longValue());
    }
    if (field.isAnnotationPresent(Size.class)) {
        Size sizeAnnotation = field.getAnnotation(Size.class);
        int minSize = sizeAnnotation.min();
        int maxSize = sizeAnnotation.max();
        result = RandomStringUtils.randomAlphabetic(new RandomDataGenerator().nextInt(minSize, maxSize));
    }
    return result;

}