| 15 | /// result of a multiplication of two `BigDecimal`s returns a |
| 16 | /// `BigDecimal` with double scale. |
| 17 | public class BigDecimal { |
| 18 | //private final BigInteger bigInt; |
| 19 | //private final int scale; |
| 20 | |
| 21 | TBigDecimal peer; |
| 22 | |
| 23 | /// Constructor for `BigDecimal`. The value of the |
| 24 | /// constructed `BigDecimal` equals `bigInt / 10scale`. |
| 25 | /// |
| 26 | /// #### Parameters |
| 27 | /// |
| 28 | /// - `bigInt`: The `bigInt` value parameter. |
| 29 | /// |
| 30 | /// - `scale`: The scale of the constructed `BigDecimal`. |
| 31 | public BigDecimal(BigInteger bigInt, int scale) { |
| 32 | peer = new TBigDecimal(bigInt.peer, scale); |
| 33 | } |
| 34 | |
| 35 | private BigDecimal(BigDecimal limBigDec) { |
| 36 | peer = new TBigDecimal(limBigDec.toString()); |
| 37 | } |
| 38 | |
| 39 | private BigDecimal(TBigDecimal peer) { |
| 40 | this.peer = peer; |
| 41 | } |
| 42 | |
| 43 | /// Returns a `BigDecimal` with value `value / 2scale / 10scale` |
| 44 | /// |
| 45 | /// #### Parameters |
| 46 | /// |
| 47 | /// - `value`: @param value The value of the `BigDecimal` to be |
| 48 | /// created. |
| 49 | /// |
| 50 | /// - `scale`: @param scale The scale of the `BigDecimal` to be |
| 51 | /// created. |
| 52 | /// |
| 53 | /// #### Returns |
| 54 | /// |
| 55 | /// The such created `BigDecimal`. |
| 56 | /// |
| 57 | /// #### Deprecated |
| 58 | /// |
| 59 | /// @deprecated This method is not part of the JDK's `BigDecimal` class and its presence is historical, |
| 60 | /// as the first implementation of Codename One's BigDecimal class was ported from BouncyCastle, which is different |
| 61 | /// than the JDK's BigDecimal class in that is optimizes binary arithmetic. The implementation of this method |
| 62 | /// is counter-intuitive since it performs a bitwise left shift on `value` before scaling it. Use `int)` |
| 63 | /// instead if you just want to convert a `BigInteger` into a `BigDecimal`. **Do not rely on this method |
| 64 | /// as it will be removed in a future version of Codename One.**. |
| 65 | public static BigDecimal getInstance(BigInteger value, int scale) { |
| 66 | return new BigDecimal(value.shiftLeft(scale), scale); |
| 67 | } |
| 68 | |
| 69 | public BigDecimal adjustScale(int newScale) { |
| 70 | return new BigDecimal(peer.setScale(newScale)); |
| 71 | } |
| 72 | |
| 73 | public BigDecimal add(BigDecimal b) { |
| 74 | return new BigDecimal(peer.add(b.peer)); |
nothing calls this directly
no outgoing calls
no test coverage detected