# URL with decimals. How to allow in routes?

**URL:** <https://www.ruby-forum.com/t/url-with-decimals-how-to-allow-in-routes/141688>\
**Category:** Rails\
**Created:** [June 29, 2008, 1:11pm UTC](https://www.ruby-forum.com/t/url-with-decimals-how-to-allow-in-routes/141688 "2008-06-29T13:11:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [June 29, 2008, 1:11pm UTC](https://www.ruby-forum.com/t/url-with-decimals-how-to-allow-in-routes/141688/1 "2008-06-29T13:11:30Z")

</div>

Hi,

I have a resource that can take latitue and longitude. I have defined  
those in the DB as:

t.decimal :lat, :precision =\> 15, :scale =\> 10  
t.decimal :lng, :precision =\> 15, :scale =\> 10

I have set the route so I can pass those in a restful way:

map.nearby ‘/messages/nearby/:lat/:lng/:range/’,  
:controller =\> ‘nearbies’,  
:action =\> ‘index’,  
:conditions =\> {:method =\> :get}

So I can pass a URL like:  
[http://127.0.0.1](http://127.0.0.1).:3000/messages/nearby/0,4/1,3/73

However the 0,4 and 1,3 are strings and when they are used for latitude  
and longitude they become 0.0 and 1.0

I see two options:

1- Convert 0,4 to 0.4 (I need decimal, :precision =\> 15, :scale =\> 10)  
2- Allow decimals in the URL (…messages/nearby/0.4/1.3/73)

Is option #2 possible?  
Any hints to realize any of them?  
I have not succeeded converting the string…

Thanks

---

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [June 29, 2008, 7:38pm UTC](https://www.ruby-forum.com/t/url-with-decimals-how-to-allow-in-routes/141688/2 "2008-06-29T19:38:22Z")

</div>

> 1- Convert 0,4 to 0.4 (I need decimal, :precision =\> 15, :scale =\> 10)

Went for option #1:

fixlat = params[:lat].gsub(/[,]/, ‘.’)  
fixlat.to\_f

So far looks ok.

Cheers.
