るりまサーチ

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

別のキーワード

  1. _builtin >
  2. bigdecimal >
  3. module >
  4. integer >
  5. complex >

ライブラリ

クラス

キーワード

検索結果

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

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

...、小数点以上の指定された位で四捨五入されます。
@param half ちょうど半分の値の丸め方を指定します。
サポートされている値は以下の通りです。

* :up or nil: 0から遠い方に丸められます。
* :even: もっとも近い偶数に...
.../emlist[例][ruby]{
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) # => 93...
...50
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#t...

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

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

...、小数点以上の指定された位で四捨五入されます。
@param half ちょうど半分の値の丸め方を指定します。
サポートされている値は以下の通りです。

* :up or nil: 0から遠い方に丸められます。
* :even: もっとも近い偶数に...
.../emlist[例][ruby]{
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) # => 93...
...50
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#t...

Integer#round(ndigits = 0, half: :up) -> Integer (18391.0)

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

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

@param ndigits 10進数での小数点以下の有効桁数を整数で指定します。
負の整数を指定した場合、小数点位置から左に少なくとも n 個の 0 が並びます。
@param half ちょうど半分の...
...:up or nil: 0から遠い方に丸められます。
* :even: もっとも近い偶数に丸められます。
* :down: 0に近い方に丸められます。

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

25.round(-1, half: :up)...
...=> 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: :even) # =>...

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

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

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

@param ndigits 10進数での小数点以下の有効桁数を整数で指定します。
正の整数を指定した場合、Float を返します。
小数点以下を、最大 n 桁にします。...
...half ちょうど半分の値の丸め方を指定します。
サポートされている値は以下の通りです。

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

//emlis...
....round # => 1
1.round(2) # => 1.0
15.round(-1) # => 20
(-15).round(-1) # => -20

25.round(-1, half: :up) # => 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...

BigDecimal.limit(n = nil) -> Integer (6323.0)

生成されるBigDecimalオブジェクトの最大桁数をn桁に制限します。 n を指定しない、または n が nil の場合は、現状の最大桁数が返ります。

...生成されるBigDecimalオブジェクトの最大桁数をn桁に制限します。
n を指定しない、または n が nil の場合は、現状の最大桁数が返ります。

戻り値は設定する前の値です。設定値のデフォルト値は0で、桁数無制限を表してい...
... limit で
予め桁数を制限できます。この場合 BigDecimal.mode で指定された丸め処理が
実行されます。ただし、インスタンスメソッド (BigDecimal#truncate /
BigDecimal#round / BigDecimal#ceil / BigDecimal#floor /
BigDecimal#add/ BigDecimal#sub / BigDecimal#mul...
...t /
BigDecimal#div) の桁数制限は limit より優先されます。

//emlist[][ruby]{
require 'bigdecimal'
n = 0 # デフォルト値
mf = BigDecimal::limit(n)
//}

@param n 新しい最大桁数を正の整数で指定します。

@raise ArgumentError n に負の数を指定した場合に...

絞り込み条件を変える

BigDecimal.mode(s) -> Integer | nil (3404.0)

BigDecimal の計算処理の制御方法を設定、確認します。

...BigDecimal の計算処理の制御方法を設定、確認します。

第2引数を省略、または nil を指定すると現状の設定値を返します。

@param s 制御方法の設定、確認を行う項目を BigDecimal::EXCEPTION_*、
BigDecimal::ROUND_MODE のいずれか...
...param v 引数 s が BigDecimal::ROUND_MODE の場合は
BigDecimal::ROUND_MODE 以外の BigDecimal::_ROUND* のいず
れかを指定します。指定した丸め処理が有効になります。
それ以外の場合は、true、false、nil のいずれかを指定し...
...、false を指定した場合
は設定値が無効になります。

@raise TypeError 引数 s に有効でない値を指定した場合に発生します。

@raise ArgumentError 引数 s に例外処理に関する値を指定し、引数 v に
true、false 以外...

BigDecimal.mode(s, v) -> Integer | nil (3404.0)

BigDecimal の計算処理の制御方法を設定、確認します。

...BigDecimal の計算処理の制御方法を設定、確認します。

第2引数を省略、または nil を指定すると現状の設定値を返します。

@param s 制御方法の設定、確認を行う項目を BigDecimal::EXCEPTION_*、
BigDecimal::ROUND_MODE のいずれか...
...param v 引数 s が BigDecimal::ROUND_MODE の場合は
BigDecimal::ROUND_MODE 以外の BigDecimal::_ROUND* のいず
れかを指定します。指定した丸め処理が有効になります。
それ以外の場合は、true、false、nil のいずれかを指定し...
...、false を指定した場合
は設定値が無効になります。

@raise TypeError 引数 s に有効でない値を指定した場合に発生します。

@raise ArgumentError 引数 s に例外処理に関する値を指定し、引数 v に
true、false 以外...

NKF (48.0)

nkf(Network Kanji code conversion Filter, https://osdn.net/projects/nkf/) を Ruby から使うためのモジュールです。

...rsion Filter, https://osdn.net/projects/nkf/) を
Ruby から使うためのモジュールです。

=== 使い方

以下は、漢字コード変換コマンドの例です。

//emlist[例][ruby]{
#!/usr/local/bin/ruby

require 'nkf'

opt = ''
opt = ARGV.shift if ARGV[0][0] == ?-

while line = AR...
... line)
end
//}

以下は、漢字コード判別コマンドの例です。

//emlist[例][ruby]{
#!/usr/local/bin/ruby

require 'nkf'

CODES = {
NKF::JIS => "JIS",
NKF::EUC => "EUC",
NKF::SJIS => "SJIS",
NKF::UTF8 => "UTF8",
NKF::BINARY => "BINARY",
NKF::ASCII =>...
..."ASCII",
NKF::UNKNOWN => "UNKNOWN",
}

while file = ARGV.shift
str = open(file) {|io| io.gets(nil) }

printf "%-10s ", file
if str.nil?
puts "EMPTY"
else
puts CODES.fetch(NKF.guess(str))
end
end
//}

=== オプション文字列

-b 入力がバッファリングされる(...