78
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2007 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 ******************************************************************************/
|
|
11
|
|
12 module org.eclipse.core.internal.databinding.conversion.NumberToBigDecimalConverter;
|
|
13
|
|
14 import java.lang.all;
|
|
15
|
|
16 import java.math.BigDecimal;
|
|
17 import java.math.BigInteger;
|
|
18
|
|
19 import com.ibm.icu.text.NumberFormat;
|
|
20
|
|
21 /**
|
|
22 * Converts from a Number to a BigDecimal.
|
|
23 * <p>
|
|
24 * Class is thread safe.
|
|
25 * </p>
|
|
26 *
|
|
27 * @since 1.0
|
|
28 */
|
|
29 public class NumberToBigDecimalConverter : NumberToNumberConverter {
|
|
30 /**
|
|
31 * @param numberFormat
|
|
32 * @param fromType
|
|
33 */
|
|
34 public this(NumberFormat numberFormat, ClassInfo fromType) {
|
|
35 super(numberFormat, fromType, BigDecimal.classinfo);
|
|
36 }
|
|
37
|
|
38 /* (non-Javadoc)
|
|
39 * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number)
|
|
40 */
|
|
41 protected Number doConvert(Number number) {
|
|
42 if ( null !is cast(BigInteger)number ) {
|
|
43 return new BigDecimal(cast(BigInteger) number);
|
|
44 }
|
|
45
|
|
46 return new BigDecimal(number.doubleValue());
|
|
47 }
|
|
48 }
|