るりまサーチ

最速Rubyリファレンスマニュアル検索!
50件ヒット [1-50件を表示] (0.016秒)
トップページ > クエリ:Float[x] > クエリ:*[x] > クエリ:round[x]

別のキーワード

  1. _builtin float
  2. float to_d
  3. json float
  4. float rationalize
  5. fiddle type_float

ライブラリ

クラス

キーワード

検索結果

Float#round(ndigits = 0) -> Integer | Float (39348.0)

自身ともっとも近い整数もしくは実数を返します。

...方を指定します。
サポートされている値は以下の通りです。

*
:up or nil: 0から遠い方に丸められます。
*
:even: もっとも近い偶数に丸められます。
*
:down: 0に近い方に丸められます。

@return 指定された引数に応じて、...
...]{
1.0.round # => 1
1.2.round # => 1
(-1.2).round # => -1
(-1.5).round # => -2

t = Math::PI # => 3.141592653589793
t.round(3) # => 3.142
t.round(0) # => 3
t.round(1) # => 3.1

t = t**10 # => 93648.04747608298
t.round(-0) # => 93648
t.round(-1) # => 93650
t.round(-2)...
...# => 93600
t.round(-3) # => 94000
t.round(-100) # => 0

2.5.round(half: :up) # => 3
2.5.round(half: :even) # => 2
2.5.round(half: :down) # => 2
3.5.round(half: :up) # => 4
3.5.round(half: :even) # => 4
3.5.round(half: :down) # => 3
//}

@see Float#ceil, Float#floor, Float#truncate...

Float#round(ndigits = 0, half: :up) -> Integer | Float (39348.0)

自身ともっとも近い整数もしくは実数を返します。

...方を指定します。
サポートされている値は以下の通りです。

*
:up or nil: 0から遠い方に丸められます。
*
:even: もっとも近い偶数に丸められます。
*
:down: 0に近い方に丸められます。

@return 指定された引数に応じて、...
...]{
1.0.round # => 1
1.2.round # => 1
(-1.2).round # => -1
(-1.5).round # => -2

t = Math::PI # => 3.141592653589793
t.round(3) # => 3.142
t.round(0) # => 3
t.round(1) # => 3.1

t = t**10 # => 93648.04747608298
t.round(-0) # => 93648
t.round(-1) # => 93650
t.round(-2)...
...# => 93600
t.round(-3) # => 94000
t.round(-100) # => 0

2.5.round(half: :up) # => 3
2.5.round(half: :even) # => 2
2.5.round(half: :down) # => 2
3.5.round(half: :up) # => 4
3.5.round(half: :even) # => 4
3.5.round(half: :down) # => 3
//}

@see Float#ceil, Float#floor, Float#truncate...

Integer#round(ndigits = 0, half: :up) -> Integer | Float (18310.0)

self ともっとも近い整数を返します。

...

@param ndigits 10進数での小数点以下の有効桁数を整数で指定します。
正の整数を指定した場合、Float を返します。
小数点以下を、最大 n 桁にします。
負の整数を指定した場合、Integer を返...
...

*
:up or nil: 0から遠い方に丸められます。
*
:even: もっとも近い偶数に丸められます。
*
:down: 0に近い方に丸められます。

//emlist[][ruby]{
1.round # => 1
1.round(2) # => 1.0
15.round(-1) # => 20
(-15).round(-1) # => -20

25.round(-1, h...
...# => 30
25.round(-1, half: :down) # => 20
25.round(-1, half: :even) # => 20
35.round(-1, half: :up) # => 40
35.round(-1, half: :down) # => 30
35.round(-1, half: :even) # => 40
(-25).round(-1, half: :up) # => -30
(-25).round(-1, half: :down) # => -20
(-25).round(-1, half: :eve...

NEWS for Ruby 2.4.0 (948.0)

NEWS for Ruby 2.4.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...い。

== 2.3.0 以降の変更

=== 言語仕様の変更

*
条件式での多重代入ができるようになりました 10617
*
Symbol#to_proc でメソッド呼び出し元での Refinements が有効になりました 9451
*
Object#send や BasicObject#__send__ でメソッドを呼...
...2172
*
Enumerable#sum を追加 12217
*
Enumerable#uniq を追加 11090

*
Enumerator::Lazy
*
Enumerator::Lazy#chunk_while を追加 https://github.com/ruby/ruby/pull/1186
*
Enumerator::Lazy#uniq を追加 11090

*
File
*
File.empty? を追加 9969

*
Float
*
Float#ceil...
..., Float#floor, Float#truncate は
Float
#roundと同じように省略可能な桁を指定する引数を受け付けるようになりました。12245
*
Float#round は half というキーワード引数を受け付けるようになりました。
half には :even, :up, :down...

Numeric (142.0)

数値を表す抽象クラスです。Integer や Float などの数値クラス は Numeric のサブクラスとして実装されています。

...数値を表す抽象クラスです。Integer や Float などの数値クラス
は Numeric のサブクラスとして実装されています。

演算や比較を行うメソッド(+, -, *, /, <=>)は Numeric のサブクラスで定義されま
す。Numeric で定義されているメソッ...
...ているメソッド
(+, -, *, /, %) を利用して定義されるものがほとんどです。
つまり Numeric で定義されているメソッドは、Numeric のサブクラスとして新たに数値クラスを定義した時に、
演算メソッド(+, -, *, /, %, <=>, coerce)だけを...
...- - - o
remainder | o - - o - - -
round
| o o - - o o -
singleton_method_added | o - -...
...r Float Rational Complex
--------------------------------------------------------------------------------
rectangular | o - - - o
remainder | o o - - -
round
...

絞り込み条件を変える

bigdecimal (96.0)

bigdecimal は浮動小数点数演算ライブラリです。 任意の精度で 10 進表現された浮動小数点数を扱えます。

...常) 数値に自動変換することはできません。
文字列を数値に自動変換したい場合は bigdecimal.c の
「/* #define ENABLE_NUMERIC_STRING */」のコメントを外してから、
再コンパイル、再インストールする必要があります。
文字列で数値...
...2.0 / 3.0
# => 0.6666666666 67e0
//}

: truncate, round, ceil, floor

これらのメソッドは小数点からの相対位置を指定して桁数を決定します。

//emlist[][ruby]{
require "bigdecimal"
p BigDecimal("6.66666666666666").round(12).to_s(10)
# => 0.6666666666 667e1
//}

====...
...といった関数が使用できるようになります。
使用方法など、詳細は bigdecimal/math を参照して下さい。 その他、Float との相互変換などの
メソッドが bigdecimal/util でサポートされています。利用するには

//emlist[][ruby]{
require "big...