Example usage for javax.xml.bind DatatypeConverter printFloat

List of usage examples for javax.xml.bind DatatypeConverter printFloat

Introduction

In this page you can find the example usage for javax.xml.bind DatatypeConverter printFloat.

Prototype

public static String printFloat(float val) 

Source Link

Document

Converts a float value into a string.

Usage

From source file:com.actian.ilabs.dataflow.stringtemplate.runner.RunStringTemplate.java

private String FormatFieldValue(ScalarInputField field) {
    ScalarTokenType type = field.getType();
    String valueString = "";

    if (type.equals(TokenTypeConstant.BOOLEAN)) {
        BooleanInputField boolField = (BooleanInputField) field;
        valueString = DatatypeConverter.printBoolean(boolField.asBoolean());
    } else if (type.equals(TokenTypeConstant.BINARY)) {
        BinaryInputField binField = (BinaryInputField) field;
        valueString = DatatypeConverter.printHexBinary(binField.asBinary());
    } else if (type.equals(TokenTypeConstant.CHAR)) {
        CharInputField charField = (CharInputField) field;
        valueString = charField.toString();
    } else if (type.equals(TokenTypeConstant.DATE)) {
        DateInputField dateField = (DateInputField) field;
        DateFormatter dateFormatter = new DateFormatter("yyyyMMdd");
        dateFormatter.setSource(dateField);
        valueString = dateFormatter.format();
    } else if (type.equals(TokenTypeConstant.DOUBLE)) {
        DoubleInputField doubleField = (DoubleInputField) field;
        valueString = DatatypeConverter.printDouble(doubleField.asDouble());
    } else if (type.equals(TokenTypeConstant.FLOAT)) {
        FloatInputField floatField = (FloatInputField) field;
        valueString = DatatypeConverter.printFloat(floatField.asFloat());
    } else if (type.equals(TokenTypeConstant.INT)) {
        IntInputField intField = (IntInputField) field;
        valueString = DatatypeConverter.printInt(intField.asInt());
    } else if (type.equals(TokenTypeConstant.LONG)) {
        LongInputField longField = (LongInputField) field;
        valueString = DatatypeConverter.printLong(longField.asLong());
    } else if (type.equals(TokenTypeConstant.NUMERIC)) {
        NumericInputField numericField = (NumericInputField) field;
        valueString = DatatypeConverter.printDecimal(numericField.asBigDecimal());
    } else if (type.equals(TokenTypeConstant.STRING)) {
        StringInputField stringField = (StringInputField) field;
        valueString = DatatypeConverter.printString(stringField.asString());
    } else if (type.equals(TokenTypeConstant.TIME)) {
        TimeInputField timeField = (TimeInputField) field;
        TimeFormatter timeFormatter = new TimeFormatter("HHmmss.SSSZ");
        timeFormatter.setSource(timeField);
        valueString = timeFormatter.format();
    } else if (type.equals(TokenTypeConstant.TIMESTAMP)) {
        TimestampInputField timestampField = (TimestampInputField) field;
        TimestampFormatter timestampFormatter = new TimestampFormatter("yyyyMMdd'T'HHmmss.SSSZ");
        timestampFormatter.setSource(timestampField);
        valueString = timestampFormatter.format();
    } else {/* ww w  .  j  ava2s . c o  m*/
        valueString = "";
    }

    return valueString;
}