fromString

Summary

Converts a string to a double value.

Usage

public static double fromString(string numberAsStr)

Returns

The double equivalent of the string value or NaN (0) if the string is not a numeric value.

Parameters

numberAsStr

The string value to convert.

Description

Converts a string to a double value.

import System;

double x = Double.fromString("100");
Console.log(x); // 100

If the string being converted is not a valid numeric value, NaN (not a number, System.Double.NaN) is returned.

import System;

double x = Double.fromString("abc");
Console.log(x); // NaN

Additionally, scientific notation, hexadecimal notation, octal numbers, +Infinity (positive infinity), and -Infinity (negative infinity) values are allowed for string values.

import System;

double hex = Double.fromString("0xFF");
Console.log(hex); // 255

If the string value being converted is outside the range of the double data type (-1.79769313486232e308 to 1.79769313486232e308), Infinity will be returned for positive numbers and -Infinity will be returned for negative numbers.

Examples

Basic Usage
1
2
3
4
import System;
 
double x = Double.fromString("100");
Console.log(x); // 100

Share

HTML | BBCode | Direct Link