Here you can find the source of bigDecimalToByte(BigDecimal num)
Parameter | Description |
---|---|
num | a parameter |
public static byte[] bigDecimalToByte(BigDecimal num)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; import java.math.BigInteger; public class Main { /**//from w w w. j a va 2s .c o m * This method will convert a big decimal value to bytes * * @param num * @return */ public static byte[] bigDecimalToByte(BigDecimal num) { BigInteger sig = new BigInteger(num.unscaledValue().toString()); int scale = num.scale(); byte[] bscale = new byte[] { (byte) (scale) }; byte[] buff = sig.toByteArray(); byte[] completeArr = new byte[buff.length + bscale.length]; System.arraycopy(bscale, 0, completeArr, 0, bscale.length); System.arraycopy(buff, 0, completeArr, bscale.length, buff.length); return completeArr; } }