All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.dmg.pmml.adapters.NumberUtil Maven / Gradle / Ivy

There is a newer version: 1.6.6
Show newest version
/*
 * Copyright (c) 2019 Villu Ruusmann
 */
package org.dmg.pmml.adapters;

import javax.xml.bind.DatatypeConverter;

public class NumberUtil {

	private NumberUtil(){
	}

	static
	public Integer parseInteger(String value){
		return DatatypeConverter.parseInt(value);
	}

	static
	public String printInteger(Integer value){
		return DatatypeConverter.printInt(value);
	}

	static
	public Number parseNumber(String value){

		try {
			return DatatypeConverter.parseInt(value);
		} catch(NumberFormatException nfe){
			return DatatypeConverter.parseDouble(value);
		}
	}

	static
	public String printNumber(Number value){

		if(value instanceof Float){
			return DatatypeConverter.printFloat(value.floatValue());
		} else

		if(value instanceof Double){
			return DatatypeConverter.printDouble(value.doubleValue());
		} else

		{
			return value.toString();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy