Java Code Examples for com.ibm.icu.math.BigDecimal#valueOf()

The following examples show how to use com.ibm.icu.math.BigDecimal#valueOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AxesRenderHelper.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void initialize( ) throws ChartException
{
	dAxisValue = Methods.asDouble( sc.getMinimum( ) ).doubleValue( );
	dAxisStep = Methods.asDouble( sc.getStep( ) ).doubleValue( );
	
	if ( sc.isBigNumber( ) )
	{
		bdAxisValue = BigDecimal.valueOf( dAxisValue )
				.multiply( sc.getBigNumberDivisor( ),
						NumberUtil.DEFAULT_MATHCONTEXT );
		bdAxisStep = BigDecimal.valueOf( dAxisStep );
		if ( axModel.getFormatSpecifier( ) == null )
		{
			df = sc.computeDecimalFormat( bdAxisValue, bdAxisStep.multiply( sc.getBigNumberDivisor( ), NumberUtil.DEFAULT_MATHCONTEXT ) );
		}
	}
	else
	{
		if ( axModel.getFormatSpecifier( ) == null )
		{
			df = sc.computeDecimalFormat( dAxisValue, dAxisStep );
		}
	}
}
 
Example 2
Source File: AxesRenderHelper.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void initialize( ) throws ChartException
{
	dAxisValue = Methods.asDouble( sc.getMinimum( ) ).doubleValue( );
	dAxisStep = Methods.asDouble( sc.getStep( ) ).doubleValue( );
	if ( sc.isBigNumber( ) )
	{
		bdAxisValue = BigDecimal.valueOf( dAxisValue ).multiply( sc.getBigNumberDivisor( ), NumberUtil.DEFAULT_MATHCONTEXT );
		bdAxisStep = BigDecimal.valueOf( dAxisStep );
		if ( axModel.getFormatSpecifier( ) == null )
		{
			df = sc.computeDecimalFormat( bdAxisValue, bdAxisStep );
		}
	}
	else
	{
		if ( axModel.getFormatSpecifier( ) == null )
		{
			df = sc.computeDecimalFormat( dAxisValue, dAxisStep );
		}
	}
}
 
Example 3
Source File: NumberUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This method wraps number as big decimal.
 * 
 * @param n
 * @return
 */
public static BigDecimal asBigDecimal( Number n )
{
	if ( n == null )
	{
		return null;
	}
	else if ( n instanceof BigNumber )
	{
		return ((BigNumber)n).getValue( );
	}
	else if ( n instanceof BigDecimal )
	{
		return (BigDecimal) n;
	}
	else if ( n instanceof java.math.BigDecimal )
	{
		return  new BigDecimal(( (java.math.BigDecimal) n ).toString( ) );
	}
	else if ( n instanceof BigInteger )
	{
		return new BigDecimal( n.toString( ) );
	}
	
	return BigDecimal.valueOf( n.doubleValue( ) );
}
 
Example 4
Source File: DrbImageManager.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * The method orders the passed images by their location ordered by rows.
 * The sort algorithm is based on MGRS (Military grid reference system) 
 * definition (See
 * https://en.wikipedia.org/wiki/Military_grid_reference_system for 
 * details).
 * Tile ID is composed by the following pattern: _TXXXxx (5 x), these 'x' 
 * define MGRS location as followed:
 *   XXX: Grid Zone Designation (UTM zone + latitude letter C-X omitting 
 *      I and O)
 *   xx: the 100,000-meter square identifier. 100km square inside the GZD.
 *      The identification consists of a column letter (A–Z, omitting I 
 *      and O) followed by a row letter (A–V, omitting I and O).
 *      
 *   i.e: S2A_OPER_MSI_L1C_TL_SGS__20150621T042634_A005374_T17UPU_B01.jp2
 *   or   S2A_OPER_PVI_L1C_TL_SGS__20150621T042634_A005374_T17UPU.jp2
 *   The MGRS designator is located at [50-55]
 *   
 *   The use of TreeMap ensure keys are lexicographically ordered and 
 *   keep in memory the key as the grid zone descriptor, row index and 
 *   column index in this reference. 
 * @param image the image add
 * @return -1 if image insertion not possible, 0 otherwise.
 */
public int put(DrbImage image)
{
   String name = image.getName();
   String mgrs = getMGRSFromName(name);
   
   // Retrieve lat/lon location of this image
   TMCoord coord = Coordinates.tmFromMgrs(mgrs, getCentralMeridian());
   // As UTM images are 100km/100km no need to have a more fine precision.
   BigDecimal northing = BigDecimal.valueOf(
      round(coord.getNorthing()/100000,0)*100000); 
   BigDecimal easting = BigDecimal.valueOf(
      round(coord.getEasting()/100000,0)*100000);

   // Save image coordinates
   northings.add(northing);
   eastings.add(easting);
   
   // Residu of UTM 
   Integer hzone=0;
   
   if (!containsKey(hzone))
   {
      put(hzone, new Rows());
   }
   Rows rows = get(hzone);
   return rows.put(image, northing, easting);
}
 
Example 5
Source File: AutoScale.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
AxisValueProvider(double dAxisValue, double dAxisStep, AutoScale as, ScaleInfo si )
{
	this.dAxisValue = dAxisValue;
	this.dAxisStep = dAxisStep;
	this.as = as;
	this.si = si;
	if ( as.isBigNumber( ) )
	{
		this.bdAxisValue = BigDecimal.valueOf( dAxisValue ).multiply( as.getBigNumberDivisor( ),
				NumberUtil.DEFAULT_MATHCONTEXT );
		this.bdAxisStep = BigDecimal.valueOf( dAxisStep );
		this.bdStep = bdAxisStep.multiply( as.getBigNumberDivisor( ),
				NumberUtil.DEFAULT_MATHCONTEXT );
	}	
}
 
Example 6
Source File: NumberUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This method wraps number as big number.
 * 
 * @param n
 * @param divisor
 * @return
 */
public static BigNumber asBigNumber( Number n, BigDecimal divisor )
{
	if ( n == null )
	{
		return null;
	}
	else if ( n instanceof Double )
	{
		if ( ( (Double) n ).isNaN( ) )
		{
			return new BigNumber(BigDecimal.ZERO, divisor ); 
		}
		return new BigNumber(BigDecimal.valueOf( ((Double)n ).doubleValue( )), divisor );
	}
	else if ( n instanceof BigDecimal )
	{
		return new BigNumber( (BigDecimal)n, divisor );
	}
	else if ( n instanceof java.math.BigDecimal )
	{
		return new BigNumber( asBigDecimal( n ), divisor );
	}
	else if ( n instanceof BigNumber )
	{
		((BigNumber)n).setDivisor( divisor );
		return (BigNumber) n;
	}
	
	return new BigNumber(BigDecimal.valueOf( n.doubleValue( )), divisor );
}