6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Elixir Float

Posted at

Elixir Float

概要

Elixir の Float について。

組み込み関数

下記を参照
http://elixir-lang.org/docs/stable/elixir/Float.html

ceil(number, precision \ 0)

切り上げ。
precision は小数点以下桁数

iex> Float.ceil(1.4)
2.0
iex> Float.ceil(1.5)
2.0
iex> Float.ceil(1.555, 2)
1.56
iex> Float.ceil(1.554, 2)
1.56

floor(number, precision \ 0)

切り捨て。
precision は小数点以下桁数

iex> Float.floor(1.4)
1.0
iex> Float.floor(1.5)
1.0
iex> Float.floor(1.555, 2)
1.55
iex> Float.floor(1.554, 2)
1.55

round(number, precision \ 0)

四捨五入。
precision は小数点以下桁数

iex> Float.round(1.4)
1.0
iex> Float.round(1.5)
2.0
iex> Float.round(1.555, 2)
1.56
iex> Float.round(1.554, 2)
1.55

parse(binary)

binary を Float に変換します

iex> Float.parse("234")
{234.0, ""}
iex> Float.parse("234.5")
{234.5, ""}
iex> Float.parse("234.5abc")
{234.5, "abc"}
iex> Float.parse("not number")
:error

to_char_list(number)

Float を char_list に変換します

iex> Float.to_char_list(234.0)
'2.34000000000000000000e+02'
iex> Float.to_char_list(234.5)
'2.34500000000000000000e+02'

to_char_list(float, options)

Float を char_list に変換します。

options

  • :decimals — 十進表記
  • :scientific — 指数表記
iex> Float.to_char_list(35.555, [decimals: 2])
'35.56'
iex> Float.to_char_list(35.555, [scientific: 2])
'3.56e+01'

to_string(some_float)

Float を string に変換します

iex> Float.to_string(234.0)
"2.34000000000000000000e+02"
iex> Float.to_string(234.5)
"2.34500000000000000000e+02"

to_string(float, options)

Float を char_list に変換します。

options

  • :decimals — 十進表記
  • :scientific — 指数表記
iex> Float.to_string(35.555, [decimals: 2])
"35.56"
iex> Float.to_string(35.555, [scientific: 2])
"3.56e+01"

参照

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?