Linux command
float 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Declare a float variable
float [myvar]=3.14
Declare multiple float variables
float [x]=1.5 [y]=2.7
Declare a float with arithmetic expression
float [result]='10.0 / 3.0'
List all float variables
float
Declare a float and export
float -x [myvar]=9.81
Make a float variable read-only
float -r [PI]=3.14159265
说明
float is a zsh builtin command that declares variables with the floating-point attribute. It is equivalent to typeset -E, causing the variable to be stored and displayed in floating-point (scientific) notation. When a value is assigned to a float variable, zsh performs arithmetic evaluation, allowing expressions like `float x=1.0/3.0`. The result is stored as a double-precision floating-point number. Variables declared with float display in scientific notation by default (e.g., `3.1400000000000000e+00`). Without arguments, float lists all currently declared floating-point variables and their values.
参数
- -g
- Create global variable when used inside a function
- -h
- Hide variable; do not export to child processes even if exported in outer scope
- -l
- Left-justify and strip leading blanks
- -r
- Make variable read-only
- -t
- Tag the variable (user-defined attribute)
- -u
- Force uppercase on assignment (for string context)
- -x
- Export variable to environment of child processes
- +_attr_
- Remove the specified attribute
FAQ
What is the float command used for?
float is a zsh builtin command that declares variables with the floating-point attribute. It is equivalent to typeset -E, causing the variable to be stored and displayed in floating-point (scientific) notation. When a value is assigned to a float variable, zsh performs arithmetic evaluation, allowing expressions like `float x=1.0/3.0`. The result is stored as a double-precision floating-point number. Variables declared with float display in scientific notation by default (e.g., `3.1400000000000000e+00`). Without arguments, float lists all currently declared floating-point variables and their values.
How do I run a basic float example?
Run `float [myvar]=3.14` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -g do in float?
Create global variable when used inside a function