# Deciml

**URL:** <https://www.ruby-forum.com/t/deciml/186341>\
**Category:** Rails\
**Created:** [April 5, 2010, 10:54am UTC](https://www.ruby-forum.com/t/deciml/186341 "2010-04-05T10:54:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [April 5, 2010, 10:54am UTC](https://www.ruby-forum.com/t/deciml/186341/1 "2010-04-05T10:54:40Z")

</div>

Hi  
In my table I have  
t.decimal :rent, :precision =\> 12, :scale =\> 2

```
But when ever I enter a large value like

```

1234567890333.465

```
To the table it is stored as 9999999999.99

     I would like to know how active record validation can be

```

applied here?

Thanks  
Tom

---

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [April 5, 2010, 11:25am UTC](https://www.ruby-forum.com/t/deciml/186341/2 "2010-04-05T11:25:34Z")

</div>

On 5 April 2010 09:54, Tom M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> applied here?  
> Have a look at the rails guide on validations at  
> [http://guides.rubyonrails.org](http://guides.rubyonrails.org). Particularly validates\_numericality\_of  
> which allows a range of values to be specified.

Colin

---

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [April 5, 2010, 1:54pm UTC](https://www.ruby-forum.com/t/deciml/186341/3 "2010-04-05T13:54:01Z")

</div>

Hi,  
When you set field to decimal than default it accept 10 digits. so  
when you add the value over the limit it set to maximum decimal value.

```
 Add two validation in this case:

 a. validates_length_of - for length of decimal
 b. validates_numericality_of - for digits only
```

---

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [April 5, 2010, 2:46pm UTC](https://www.ruby-forum.com/t/deciml/186341/4 "2010-04-05T14:46:04Z")

</div>

Hi  
Thanks for all your reply

Tom

---

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [April 5, 2010, 2:22pm UTC](https://www.ruby-forum.com/t/deciml/186341/5 "2010-04-05T14:22:55Z")

</div>

On 5 April 2010 12:54, Priyanka P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,  
> When you set field to decimal than default it accept 10 digits. so  
> when you add the value over the limit it set to maximum decimal value.
> 
> ```
> Add two validation in this case:
> 
> a. validates_length_of - for length of decimal
> b. validates_numericality_of - for digits only
> 
> ```

If validates\_numericality\_of is used with :less\_than (and probably  
:more\_than) then I think the length\_of test is not necessary.

Colin
