Data Conversion

Overview

Just as “Data” is a hugely broad topic, so is “Data Conversion”. Here we’ll focus primarily on primitive and simple object conversion, which is a very common task done in Partner and especially by scripts.

Primary Tools

There are three very important tools used in converting basic data types:

  • ConversionLib,
  • StringLib, and
  • Cog.

ConversionLib and StringLib directly address conversion chores, and Cog is useful since it provides simple conversion methods when putting and getting values out of a Cog structure. Generally, these methods defer to either ConversionLib or StringLib as appropriate.

Specific Conversion Issues

Converting Numbers to Strings

Converting numbers into Strings is a frequent need. Unfortunately the default mechanism for this in Java often converts to scientific notation, which is generally not what we want.

Most Partner methods (including Cog.getString(“foo”)) use StringLib.toString(Object) for conversion. For numbers, this uses one of two methods depending on the numeric type:

  • StringLib.doubleToString(double), or
  • StringLib.longToString(long).

The doubleToString() method is used for floating-point numbers of any precision (double or float) and longToString() is used for integer numbers of any precision (short, int, or long).

Here’s the logic used in current versions. Generally it differs in the format used and the thresholds used:

  • longToString() always uses the standard format; it should never use exponential notation
  • doubleToString uses the standard format if the number falls between a minimum and maximum threshold; otherwise it uses the exponential format.

Versions 4.5.12 and 4.12-4.15

  • standard format is #0.###
  • exponential format is 0.####E0
  • minimum threshold is 0.001
  • maximum threshold is Long.MAX_VALUE (9223372036854775807)

Versions 4.5.14 through 4.5.15

  • standard format is #0.#########
  • exponential format is 0.####E0
  • minimum threshold is 0.000000001
  • maximum threshold is 999999999

Version 5 (Boots module)

  • standard format is #0.####################
  • exponential format is 0.####E0
  • minimum threshold is 0.001
  • maximum threshold is Long.MAX_VALUE (9223372036854775807)

Table Of Contents

Previous topic

Data

Next topic

Cog

This Page