Search code examples
ballerina-swan-lake

Get decimal values from hexadecimal strings


The decimal:fromString() function does not accept hexadecimal floating-point literals as arguments, and the conversion results in a runtime error. Is there any reason for not supporting the conversion from hexadecimal strings?


Solution

  • The hex syntax is used for the exact representation of a radix 2 floating point number, and is not used to represent decimal (radix 10) numbers. That is the reason ballerina doesn't support hex literals for decimal values(See the spec section 6.5) and doesn't have a fromHexString like in float.