Example usage for java.math BigDecimal BigDecimal

List of usage examples for java.math BigDecimal BigDecimal

Introduction

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

Prototype

public BigDecimal(long val) 

Source Link

Document

Translates a long into a BigDecimal .

Usage

From source file:com.salatigacode.dao.ProductDaoTests.java

@Test
public void testSave() {
    Product p = new Product();
    p.setCode("T-001");
    p.setName("Test Product 001");
    p.setPrice(new BigDecimal("100000.01"));

    Assert.assertNull(p.getId());/*from  w w w . ja v  a  2  s . co  m*/
    pd.save(p);
    Assert.assertNotNull(p.getId());
}

From source file:org.businessmanager.web.converter.BigDecimalConverter.java

@Override
public Object getAsObject(FacesContext fc, UIComponent component, String value) {
    return new BigDecimal(value);
}

From source file:org.openmrs.module.bahmniexports.example.domain.trade.internal.GeneratingTradeItemReader.java

@Override
public Trade read() throws Exception {
    if (counter < limit) {
        counter++;//from   w  w  w . ja  v a2  s  .c  o m
        return new Trade("isin" + counter, counter, new BigDecimal(counter), "customer" + counter);
    }
    return null;
}

From source file:com.eveonline.api.repo.AccountBalanceTests.java

@Test
@Sql({ "/testGetAccountKey1000Balance.sql" })
public void testGetAccountKey1000Balance() {
    AccountBalance balance = repo.findByAccountKeyAndCorporationId(1000, 1l);
    BigDecimal expected = new BigDecimal(200000.35);
    expected = expected.setScale(2, BigDecimal.ROUND_HALF_UP);
    assertEquals("Incorrect balance for corp and account key", expected, balance.getBalance());
}

From source file:com.arya.latihan.repository.ItemRepositoryTest.java

@Test
@Transactional//w ww. j  a  v a2 s . com
public void testSave() {
    Item item = new Item();
    item.setCode("M-0000000002");
    item.setName("Susu");
    item.setPrice(new BigDecimal("5000"));
    item.setCost(new BigDecimal("4500"));
    item.setStock(new BigDecimal("25"));
    item.setExpiredDate(new DateTime(2017, 02, 10, 0, 0));
    Assert.assertNull(item.getId());
    item = itemRepository.save(item);
    Assert.assertNotNull(item.getId());
}

From source file:com.creditcloud.interestbearing.ta.message.asset.UserQueryLatestAssetResponseMessage.java

public BigDecimal getAccumulatedEarning() {
    return new BigDecimal(accumulated_earning);
}

From source file:Main.java

/**
 * convert value to given type.//from   w  w w .  ja va2s.co  m
 * null safe.
 *
 * @param value value for convert
 * @param type  will converted type
 * @return value while converted
 */
public static Object convertCompatibleType(Object value, Class<?> type) {

    if (value == null || type == null || type.isAssignableFrom(value.getClass())) {
        return value;
    }
    if (value instanceof String) {
        String string = (String) value;
        if (char.class.equals(type) || Character.class.equals(type)) {
            if (string.length() != 1) {
                throw new IllegalArgumentException(String.format("CAN NOT convert String(%s) to char!"
                        + " when convert String to char, the String MUST only 1 char.", string));
            }
            return string.charAt(0);
        } else if (type.isEnum()) {
            return Enum.valueOf((Class<Enum>) type, string);
        } else if (type == BigInteger.class) {
            return new BigInteger(string);
        } else if (type == BigDecimal.class) {
            return new BigDecimal(string);
        } else if (type == Short.class || type == short.class) {
            return Short.valueOf(string);
        } else if (type == Integer.class || type == int.class) {
            return Integer.valueOf(string);
        } else if (type == Long.class || type == long.class) {
            return Long.valueOf(string);
        } else if (type == Double.class || type == double.class) {
            return Double.valueOf(string);
        } else if (type == Float.class || type == float.class) {
            return Float.valueOf(string);
        } else if (type == Byte.class || type == byte.class) {
            return Byte.valueOf(string);
        } else if (type == Boolean.class || type == boolean.class) {
            return Boolean.valueOf(string);
        } else if (type == Date.class) {
            try {
                return new SimpleDateFormat(DATE_FORMAT).parse((String) value);
            } catch (ParseException e) {
                throw new IllegalStateException("Failed to parse date " + value + " by format " + DATE_FORMAT
                        + ", cause: " + e.getMessage(), e);
            }
        } else if (type == Class.class) {
            return forName((String) value);
        }
    } else if (value instanceof Number) {
        Number number = (Number) value;
        if (type == byte.class || type == Byte.class) {
            return number.byteValue();
        } else if (type == short.class || type == Short.class) {
            return number.shortValue();
        } else if (type == int.class || type == Integer.class) {
            return number.intValue();
        } else if (type == long.class || type == Long.class) {
            return number.longValue();
        } else if (type == float.class || type == Float.class) {
            return number.floatValue();
        } else if (type == double.class || type == Double.class) {
            return number.doubleValue();
        } else if (type == BigInteger.class) {
            return BigInteger.valueOf(number.longValue());
        } else if (type == BigDecimal.class) {
            return BigDecimal.valueOf(number.doubleValue());
        } else if (type == Date.class) {
            return new Date(number.longValue());
        }
    } else if (value instanceof Collection) {
        Collection collection = (Collection) value;
        if (type.isArray()) {
            int length = collection.size();
            Object array = Array.newInstance(type.getComponentType(), length);
            int i = 0;
            for (Object item : collection) {
                Array.set(array, i++, item);
            }
            return array;
        } else if (!type.isInterface()) {
            try {
                Collection result = (Collection) type.newInstance();
                result.addAll(collection);
                return result;
            } catch (Throwable e) {
                e.printStackTrace();
            }
        } else if (type == List.class) {
            return new ArrayList<>(collection);
        } else if (type == Set.class) {
            return new HashSet<>(collection);
        }
    } else if (value.getClass().isArray() && Collection.class.isAssignableFrom(type)) {
        Collection collection;
        if (!type.isInterface()) {
            try {
                collection = (Collection) type.newInstance();
            } catch (Throwable e) {
                collection = new ArrayList<>();
            }
        } else if (type == Set.class) {
            collection = new HashSet<>();
        } else {
            collection = new ArrayList<>();
        }
        int length = Array.getLength(value);
        for (int i = 0; i < length; i++) {
            collection.add(Array.get(value, i));
        }
        return collection;
    }
    return value;
}

From source file:ch.rasc.edsutil.PropertyComparatorTest.java

@Before
public void setup() {
    users = new ArrayList<>();
    user1 = new User(1, "Ralph", LocalDate.of(1989, 1, 23), new BigDecimal("100.05"));
    users.add(user1);/* w w w .  ja  v a 2 s. co m*/
    user3 = new User(3, "Lamar", LocalDate.of(1989, 2, 15), new BigDecimal("100.15"));
    users.add(user3);
    user2 = new User(2, "jeremy", LocalDate.of(1989, 1, 22), new BigDecimal("100.25"));
    users.add(user2);
    user5 = new User(5, "Peter", LocalDate.of(1989, 12, 12), new BigDecimal("99.25"));
    users.add(user5);
    user4 = new User(4, "Branden", LocalDate.of(1989, 6, 7), new BigDecimal("99.15"));
    users.add(user4);
}

From source file:ch.ralscha.extdirectspring.provider.Row.java

public Row(int id, String name, boolean admin, String salary) {
    super();/*  www  .  java  2  s.c  o  m*/
    this.id = id;
    this.name = name;
    this.admin = admin;
    if (salary != null) {
        this.salary = new BigDecimal(salary);
    }
}

From source file:com.greenline.guahao.biz.manager.partners.xm.converter.XmConverter.java

public static XmOrderDO convertToXmOrderDO(OrderDO o, String xmUserId, String accessToken) {
    XmOrderDO xo = null;//from   w ww .jav  a  2s  .c  o m
    if (null != o) {
        xo = new XmOrderDO();
        xo.setAccessToken(accessToken); // ?
        xo.setUserId(xmUserId);// ??
        xo.setOrderDepartment(StringUtils.defaultString(o.getHospDepartmentName())); // ??
        xo.setOrderDoctor(StringUtils.defaultString(o.getExpertName()));// ??
        xo.setOrderHospital(StringUtils.defaultString(o.getHosptialName()));// ??
        xo.setOrderId(StringUtils.defaultString(o.getOrderNo()));// ??
        xo.setOrderName(XmConstants.ORDER_NAME);// ???
        xo.setOrderPlace0(StringUtils.defaultString(o.getFetchAddress())); // ???
        xo.setOrderPlace1(StringUtils.defaultString(o.getClinicAddress())); // ?
        xo.setOrderPrice(null == o.getClinicFee() ? 0
                : new BigDecimal(o.getClinicFee()).divide(new BigDecimal(100)).setScale(2).doubleValue()); // ????
        xo.setOrderPriceInfo(xo.getOrderPlace0());// ?
        xo.setOrderShipType(StringUtils.defaultString(o.getClinicTypeName())); // 
        xo.setOrderShortInfo(getOrderShortInfo(xo));// ???<=32
        xo.setOrderStartTime(parseTimeToSecondFromYyyyMMdd(o.getClinicDate())); // 
        xo.setOrderStatus(switchOrderStatus(o.getStatus())); // ??
        xo.setOrderTime(parseTimeToSecond(o.getCreatedTime())); // ?
        xo.setOrderUrl(getOrderDetailUrl(xo)); // ??
    }
    return xo;
}