KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > databinding > conversion > NumberToBigDecimalConverter


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 package org.eclipse.core.internal.databinding.conversion;
13
14 import java.math.BigDecimal JavaDoc;
15 import java.math.BigInteger JavaDoc;
16
17 import com.ibm.icu.text.NumberFormat;
18
19 /**
20  * Converts from a Number to a BigDecimal.
21  * <p>
22  * Class is thread safe.
23  * </p>
24  *
25  * @since 1.0
26  */

27 public class NumberToBigDecimalConverter extends NumberToNumberConverter {
28     /**
29      * @param numberFormat
30      * @param fromType
31      */

32     public NumberToBigDecimalConverter(NumberFormat numberFormat, Class JavaDoc fromType) {
33         super(numberFormat, fromType, BigDecimal JavaDoc.class);
34     }
35
36     /* (non-Javadoc)
37      * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number)
38      */

39     protected Number JavaDoc doConvert(Number JavaDoc number) {
40         if (number instanceof BigInteger JavaDoc) {
41             return new BigDecimal JavaDoc((BigInteger JavaDoc) number);
42         }
43         
44         return new BigDecimal JavaDoc(number.doubleValue());
45     }
46 }
47
Popular Tags