# Float to\_s behavior

**URL:** <https://www.ruby-forum.com/t/float-to-s-behavior/146710>\
**Category:** wxRuby\
**Created:** [August 24, 2008, 2:15pm UTC](https://www.ruby-forum.com/t/float-to-s-behavior/146710 "2008-08-24T14:15:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/u/Svend_Haugaard_SSSS)\
**Post date:** [August 24, 2008, 2:15pm UTC](https://www.ruby-forum.com/t/float-to-s-behavior/146710/1 "2008-08-24T14:15:35Z")

</div>

Does wxruby change the behavior of to\_s for float ?

If I run this little program

a = [1.23,4.56,7.89]  
puts a.join(’ ')

I get the following output  
1.23 4.56 7.89

As your would expect, but if I add it to a program that uses wxruby the  
output is  
1,23 4,56 7,89

According to danish grammar(I am from Denmark) this is the correct way  
to write numbers but this charge mess with all data files I write.

How can I change it back to the original form ?

---

<div class="post-metadata">

**Author:** ![Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/u/Svend_Haugaard_SSSS)\
**Post date:** [August 24, 2008, 3:13pm UTC](https://www.ruby-forum.com/t/float-to-s-behavior/146710/2 "2008-08-24T15:13:34Z")

</div>

Hi

Svend Haugaard Sørensen wrote:

> As your would expect, but if I add it to a program that uses wxruby the  
> output is  
> 1,23 4,56 7,89
> 
> According to danish grammar(I am from Denmark) this is the correct way  
> to write numbers but this charge mess with all data files I write.

Interesting. wxRuby itself doesn’t do anything to alter the behaviour of  
Float#to\_s. The wxRuby library doesn’t change or extend any of Ruby’s  
standard classes; we consider that bad behaviour for a library.

What’s happening is that wxWidgets somewhere is calling the C setlocale  
function - I can’t quite pin it down in the Wx source at the moment.  
This affects the way that the C sprintf (and also strftime) functions  
work. Ruby calls these under the hood to implement methods like  
Float#to\_s and DateTime#strftime.

I see something similar to you. In my locale (en\_GB) our standard way of  
writing dates is DD/MM/YY (today is 24/08/2008), whereas in the US,  
people write months MM/DD/YY (today would be 08/24/2008). When I change  
wxRuby’s locale to be en\_GB, it also affects the way that Ruby methods  
like Time.now.strftime(‘%x’) work.

> How can I change it back to the original form ?

The easiest way is probably to explicitly switch to en\_US locale in the  
startup of your wxRuby application:

Wx::Locale.set\_locale(‘en\_US’)

See the documentation  
[http://wxruby.rubyforge.org/doc/locale.html](http://wxruby.rubyforge.org/doc/locale.html)

Examples of using Wx::Locale can be found in one of the tests:  
[http://wxruby.rubyforge.org/svn/trunk/wxruby2/tests/test\_intl.rb](http://wxruby.rubyforge.org/svn/trunk/wxruby2/tests/test_intl.rb)

cheers  
alex
