在Erlang中,有两种数字类型:整数(integers)和浮点数(floats)。
整数示例:
-module(helloLearnfk). -export([start/0]).start() -> io:fwrite("~w",[1+1]).
上面程序的输出如下:
2
浮点数示例:
-module(helloLearnfk). -export([start/0]).start() -> io:fwrite("~w",[1.1+1.2]).
上面程序的输出如下:
2.3
浮点数和指数
使用 fwrite 方法将值输出到控制台时,有可用的格式化参数,可用于将数字输出为浮点数或指数。
-module(helloLearnfk). -export([start/0]).start() -> io:fwrite("
fn",[1.1+1.2]), io:fwrite("en",[1.1+1.2]).
上面程序的输出如下:
2.300000 2.30000e+0
数学函数
以下数学函数可用于数字的Erlang。请注意,Erlang的所有数学函数都存在于数学库中。
| Sr.No. | Mathematical Functions & 描述 |
|---|---|
| 1 |
Sin 正弦值。 |
| 2 |
cos 余弦值。 |
| 3 |
tan 切线。 |
| 4 |
asin 反正弦值。 |
| 5 |
acos 反余弦。 |
| 6 |
atan 反正切。 |
| 7 |
exp 指定值的指数。 |
| 8 |
log 指定值的对数。 |
| 9 |
abs 绝对值。 |
| 10 |
float 浮点值。 |
| 11 |
Is_float 判断是否为浮点值。 |
| 12 |
Is_Integer 判断字是否为整数值。 |