Float32

Float32(x [, mode::RoundingMode])

Create a Float32 from x. If x is not exactly representable then mode determines how x is rounded.

julia> Float32(1/3, RoundDown)
0.3333333f0

julia> Float32(1/3, RoundUp)
0.33333334f0

See get_rounding for available rounding modes.

Examples

Float32(x [, mode::RoundingMode])

Create a Float32 from x. If x is not exactly representable, then mode determines how x is rounded.

julia> Float32(1/3, RoundDown)
0.3333333f0

julia> Float32(1/3, RoundUp)
0.33333334f0

In the above examples, Float32 is used to create a single-precision floating-point number from a given value (x). The mode parameter is optional and specifies the rounding mode to be used if x cannot be represented exactly as a Float32. The available rounding modes can be obtained using the get_rounding function.

Note: The suffix f0 in the output represents a Float32 value.

It's worth mentioning that the Float32 function can be used with various types of input, including integers, floating-point numbers, and expressions involving mathematical operations.

Example:

julia> Float32(10)
10.0f0

julia> Float32(3.14)
3.1400001f0

julia> Float32(sqrt(2))
1.4142135f0

In the first example, Float32 converts the integer 10 into a single-precision floating-point number. The second example demonstrates the conversion of the floating-point number 3.14. The third example shows the conversion of the square root of 2 using the sqrt function.

Please note that Float32 may introduce round-off errors when representing numbers that cannot be expressed exactly in binary floating-point format.

See Also

BigFloat, BigInt, Dict, eltype, fieldtype, Float32, Float64, IntSet, isa, isalnum, isalpha, isascii, iseltype, isequal, isgraph, isimmutable, isinteractive, isleaftype, isnull, ispunct, isspace, issubtype, keytype, Nullable, NullException, promote_type, typeintersect, typejoin, typemax, typemin, typeof, Val, valtype,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: