---
title: "New arguments support for float & integer modifiers"
description: "Optional argument ndigits added to ceil, floor, truncate"
canonical_url: "https://www.bigbinary.com/blog/new-ndigits-arguments-supported-for-float-modifiers-in-ruby-2-4"
markdown_url: "https://www.bigbinary.com/blog/new-ndigits-arguments-supported-for-float-modifiers-in-ruby-2-4.md"
---

# New arguments support for float & integer modifiers

Optional argument ndigits added to ceil, floor, truncate

- Author: Abhishek Jain
- Published: March 28, 2017
- Categories: Ruby 2.4, Ruby

In Ruby, there are many methods available which help us to modify a float or
integer value.

### Ruby 2.3.x

In the previous versions of Ruby, we could use methods such as `floor`, `ceil`
and `truncate` in following ways.

```ruby

5.54.floor          #=> 5
5.54.ceil           #=> 6
5.54.truncate       #=> 5

```

Providing an argument to these methods would result in `ArgumentError`
exception.

### Ruby 2.4

Ruby community decided to come up with an option to
[add precision argument](https://bugs.ruby-lang.org/issues/12245) .

The precision argument, which can be negative, helps us to get result to the
required precision to either side of the decimal point.

The default value for the precision argument is 0.

```ruby

876.543.floor(-2)       #=> 800
876.543.floor(-1)       #=> 870
876.543.floor           #=> 876
876.543.floor(1)        #=> 876.5
876.543.floor(2)        #=> 876.54

876.543.ceil(-2)        #=> 900
876.543.ceil(-1)        #=> 880
876.543.ceil            #=> 877
876.543.ceil(1)         #=> 876.6
876.543.ceil(2)         #=> 876.55

876.543.truncate(-2)    #=> 800
876.543.truncate(-1)    #=> 870
876.543.truncate        #=> 876
876.543.truncate(1)     #=> 876.5
876.543.truncate(2)     #=> 876.54

```

These methods all work the same on Integer as well.

```ruby

5.floor(2)              #=> 5.0
5.ceil(2)               #=> 5.0
5.truncate(2)           #=> 5.0

```

## Links

- [Human page](https://www.bigbinary.com/blog/new-ndigits-arguments-supported-for-float-modifiers-in-ruby-2-4)
