float
float(x)
Convert a number, array, or string to a AbstractFloat
data type. For numeric data, the smallest suitable AbstractFloat
type is used. Converts strings to Float64
.
Examples
julia> float(5)
5.0
julia> float(3.14)
3.14
julia> float([1, 2, 3])
3-element Array{Float64,1}:
1.0
2.0
3.0
julia> float("3.14")
3.14
- The
float
function can be used to convert an integer or a floating-point number to aFloat64
type. - It can also convert an array of numbers to an array of
Float64
type, preserving the original values. - Strings representing numbers can be converted to
Float64
type as well.
Common mistake example:
julia> float("hello")
ERROR: ArgumentError: invalid number format: "hello"
In this example, the input string "hello" cannot be converted to a floating-point number. Make sure to provide valid numeric values or arrays of numbers when using the float
function.
See Also
cmp, float, get_bigfloat_precision, get_rounding, get_zero_subnormals, isapprox, maxintfloat, mod2pi, nextfloat, precision, prevfloat, rationalize, round, set_bigfloat_precision, set_rounding, set_zero_subnormals, significand, with_bigfloat_precision, with_rounding,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.