Package uk.ac.starlink.ttools.func
Class Conversions
- java.lang.Object
-
- uk.ac.starlink.ttools.func.Conversions
-
public class Conversions extends java.lang.Object
Functions for converting between strings and numeric values.- Since:
- 2 Sep 2004
- Author:
- Mark Taylor (Starlink)
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
fromHex(java.lang.String hexVal)
Converts a string representing a hexadecimal number to its integer value.static byte
parseByte(java.lang.String str)
Attempts to interpret a string as a byte (8-bit signed integer) value.static double
parseDouble(java.lang.String str)
Attempts to interpret a string as a double (64-bit signed integer) value.static float
parseFloat(java.lang.String str)
Attempts to interpret a string as a float (32-bit floating point) value.static int
parseInt(java.lang.String str)
Attempts to interpret a string as an int (32-bit signed integer) value.static long
parseLong(java.lang.String str)
Attempts to interpret a string as a long (64-bit signed integer) value.static short
parseShort(java.lang.String str)
Attempts to interpret a string as a short (16-bit signed integer) value.static byte
toByte(double value)
Attempts to convert the numeric argument to a byte (8-bit signed integer) result.static double
toDouble(double value)
Converts the numeric argument to a double (64-bit signed integer) result.static float
toFloat(double value)
Attempts to convert the numeric argument to a float (32-bit floating point) result.static java.lang.String
toHex(long value)
Converts the integer argument to hexadecimal form.static int
toInteger(double value)
Attempts to convert the numeric argument to an int (32-bit signed integer) result.static long
toLong(double value)
Attempts to convert the numeric argument to a long (64-bit signed integer) result.static short
toShort(double value)
Attempts to convert the numeric argument to a short (16-bit signed integer) result.static java.lang.String
toString(boolean booleanVal)
Turns a boolean value into a string.static java.lang.String
toString(byte byteVal)
Turns a byte value into a string.static java.lang.String
toString(char charVal)
Turns a single character value into a string.static java.lang.String
toString(double fpVal)
Turns a numeric value into a string.static java.lang.String
toString(long intVal)
Turns an integer numeric value into a string.static java.lang.String
toString(java.lang.Object objVal)
Turns any object value into a string.
-
-
-
Method Detail
-
toString
public static java.lang.String toString(double fpVal)
Turns a numeric value into a string.- Parameters:
fpVal
- floating point numeric value- Returns:
- a string representation of
fpVal
-
toString
public static java.lang.String toString(long intVal)
Turns an integer numeric value into a string.- Parameters:
intVal
- integer numeric value- Returns:
- a string representation of
intVal
-
toString
public static java.lang.String toString(char charVal)
Turns a single character value into a string.- Parameters:
charVal
- character numeric value- Returns:
- a string representation of
charVal
-
toString
public static java.lang.String toString(byte byteVal)
Turns a byte value into a string.- Parameters:
byteVal
- byte numeric value- Returns:
- a string representation of
byteVal
-
toString
public static java.lang.String toString(boolean booleanVal)
Turns a boolean value into a string.- Parameters:
booleanVal
- boolean value (true or false)- Returns:
- a string representation of
booleanVal
("true
" or "false
")
-
toString
public static java.lang.String toString(java.lang.Object objVal)
Turns any object value into a string. As applied to existing string values this isn't really useful, but it means that you can applytoString
to any object value without knowing its type and get a useful return from it.- Parameters:
objVal
- non-primitive value- Returns:
- a string representation of
objVal
-
parseByte
public static byte parseByte(java.lang.String str)
Attempts to interpret a string as a byte (8-bit signed integer) value. If the input string can't be interpreted in this way, a blank value will result.- Parameters:
str
- string containing numeric representation- Returns:
- byte value of
str
-
parseShort
public static short parseShort(java.lang.String str)
Attempts to interpret a string as a short (16-bit signed integer) value. If the input string can't be interpreted in this way, a blank value will result.- Parameters:
str
- string containing numeric representation- Returns:
- byte value of
str
-
parseInt
public static int parseInt(java.lang.String str)
Attempts to interpret a string as an int (32-bit signed integer) value. If the input string can't be interpreted in this way, a blank value will result.- Parameters:
str
- string containing numeric representation- Returns:
- byte value of
str
-
parseLong
public static long parseLong(java.lang.String str)
Attempts to interpret a string as a long (64-bit signed integer) value. If the input string can't be interpreted in this way, a blank value will result.- Parameters:
str
- string containing numeric representation- Returns:
- byte value of
str
-
parseFloat
public static float parseFloat(java.lang.String str)
Attempts to interpret a string as a float (32-bit floating point) value. If the input string can't be interpreted in this way, a blank value will result.- Parameters:
str
- string containing numeric representation- Returns:
- byte value of
str
-
parseDouble
public static double parseDouble(java.lang.String str)
Attempts to interpret a string as a double (64-bit signed integer) value. If the input string can't be interpreted in this way, a blank value will result.- Parameters:
str
- string containing numeric representation- Returns:
- byte value of
str
-
toByte
public static byte toByte(double value)
Attempts to convert the numeric argument to a byte (8-bit signed integer) result. If it is out of range, a blank value will result.- Parameters:
value
- numeric value for conversion- Returns:
value
converted to type byte
-
toShort
public static short toShort(double value)
Attempts to convert the numeric argument to a short (16-bit signed integer) result. If it is out of range, a blank value will result.- Parameters:
value
- numeric value for conversion- Returns:
value
converted to type short
-
toInteger
public static int toInteger(double value)
Attempts to convert the numeric argument to an int (32-bit signed integer) result. If it is out of range, a blank value will result.- Parameters:
value
- numeric value for conversion- Returns:
value
converted to type int
-
toLong
public static long toLong(double value)
Attempts to convert the numeric argument to a long (64-bit signed integer) result. If it is out of range, a blank value will result.- Parameters:
value
- numeric value for conversion- Returns:
value
converted to type long
-
toFloat
public static float toFloat(double value)
Attempts to convert the numeric argument to a float (32-bit floating point) result. If it is out of range, a blank value will result.- Parameters:
value
- numeric value for conversion- Returns:
value
converted to type float
-
toDouble
public static double toDouble(double value)
Converts the numeric argument to a double (64-bit signed integer) result.- Parameters:
value
- numeric value for conversion- Returns:
value
converted to type double
-
toHex
public static java.lang.String toHex(long value)
Converts the integer argument to hexadecimal form.- Parameters:
value
- integer value- Returns:
- hexadecimal representation of
value
- Examples:
toHex(42) = "2a"
-
fromHex
public static int fromHex(java.lang.String hexVal)
Converts a string representing a hexadecimal number to its integer value.- Parameters:
hexVal
- hexadecimal representation of value- Returns:
- integer value represented by
hexVal
- Examples:
fromHex("2a") = 42
-
-