Hello, is there a way to format “Money”-style floats in ruby. E.g:
2111000.5756 should be written as the string “2,111,000.58”
Maybe even more configurable with the Money-style class even taking
locale into account, or at least letting the user define what kind of
tokens to use as thousand-separator and decimal-token. This can be
done in C++ (even if it’s kind of complicated). Has it been done in
ruby?
http://extensions.rubyforge.org defines Numeric#format_s (originally
written by Austin Ziegler) which gives you control over the characters
used for separator, and everything else.
Gavin
···
On Tuesday, December 9, 2003, 6:07:02 AM, saggmannen wrote:
Hello, is there a way to format “Money”-style floats in ruby. E.g:
2111000.5756 should be written as the string “2,111,000.58”
Maybe even more configurable with the Money-style class even taking
locale into account, or at least letting the user define what kind of
tokens to use as thousand-separator and decimal-token. This can be
done in C++ (even if it’s kind of complicated). Has it been done in
ruby?
This has been superseded by the Standard Library Extensions that Gavin
Sinclair has put together (he has used my code and cleaned up the interface
a little to be more “language” oriented instead of parameter heavy).
-austin
···
On Tue, 9 Dec 2003 04:22:08 +0900, Mark J. Reed wrote:
On Mon, Dec 08, 2003 at 07:06:32PM +0000, saggmannen wrote:
Hello, is there a way to format “Money”-style floats in ruby. E.g:
2111000.5756 should be written as the string “2,111,000.58”
Yes, there is. I’m sure that there’s a module in the RAA for this,
although I can’t find it at the moment. It’s not too hard to do
manually, though:
Hello, is there a way to format “Money”-style floats in ruby. E.g:
2111000.5756 should be written as the string “2,111,000.58”
Maybe even more configurable with the Money-style class even taking
locale into account, or at least letting the user define what kind of
tokens to use as thousand-separator and decimal-token. This can be
done in C++ (even if it’s kind of complicated). Has it been done in
ruby?
http://extensions.rubyforge.org defines Numeric#format_s (originally
written by Austin Ziegler) which gives you control over the characters
used for separator, and everything else.
Gavin
Gavin! I took a look at Numeric#format_s. I’m thinking this function
is doing too much. Wouldn’t it be better to separate the setup of the
“locale” from the actual formatting of the “Money”? Because the setup
is something you probably do once, but you may want to output many,
many moonies. This probably means that this can’t be a member of
“Numeric” any longer. Rather the format function has to be a member of
a separate “NumericFormat”-class (initialized with the proper
“locale”). what do you think?
···
On Tuesday, December 9, 2003, 6:07:02 AM, saggmannen wrote:
(?=\d) is a lookahead assertion that checks to see if there’s a digit ahead of the current pattern without capturing it (which is the important thing).
I don’t really understand your question. RubyForge is a breeding
ground for Ruby-related projects (hosting, CVS, distros, proj mgmt,
etc.). RAA is a searhable collection of links. ‘extensions’ is the
name - more correctly the “label” - of a project on RubyForge.
I think I listed that project on RAA as well, but the link would point
to RubyForge.
Gavin
···
On Tuesday, December 9, 2003, 8:42:02 AM, Mark wrote:
On Tue, Dec 09, 2003 at 05:55:07AM +0900, Gavin Sinclair wrote:
On Tuesday, December 9, 2003, 6:07:02 AM, saggmannen wrote:
Hello, is there a way to format “Money”-style floats in ruby. E.g:
2111000.5756 should be written as the string “2,111,000.58”
Maybe even more configurable with the Money-style class even taking
locale into account, or at least letting the user define what kind of
tokens to use as thousand-separator and decimal-token. This can be
done in C++ (even if it’s kind of complicated). Has it been done in
ruby?
http://extensions.rubyforge.org defines Numeric#format_s (originally
written by Austin Ziegler) which gives you control over the characters
used for separator, and everything else.
Gavin
Gavin! I took a look at Numeric#format_s. I’m thinking this function
is doing too much. Wouldn’t it be better to separate the setup of the
“locale” from the actual formatting of the “Money”? Because the setup
is something you probably do once, but you may want to output many,
many moonies. This probably means that this can’t be a member of
“Numeric” any longer. Rather the format function has to be a member of
a separate “NumericFormat”-class (initialized with the proper
“locale”). what do you think?
(?=\d) is a lookahead assertion that checks to see if there’s a digit
ahead of the current pattern without capturing it (which is the
important thing).
It’s just that, if I’m looking to see if some bit of functionality
has already been turned into a Ruby module, I look on the RAA.
So I was wondering if RubyForge was another place I have to look,
or if the stuff on RubyForge was linked on the RAA, or what.
-Mark
···
On Tue, Dec 09, 2003 at 06:53:42AM +0900, Gavin Sinclair wrote:
(?=\d) is a lookahead assertion that checks to see if there’s a digit
ahead of the current pattern without capturing it (which is the
important thing).
Apparently I hid my try pretty well in my reply
Peter
hits forehead
Because of the “>” in irb(main):…:…>, my mua displays it as a comment. continues to hit forehead
And that’s a very good question indeed. They are not automatically
linked. Whether they will be at some point in the future is a matter for
discussion. At the moment, it’s best to keep both sites in mind when
looking for stuff. From memory, RubyForge hosts 100+ projects and RAA
links to 700+ projects. Many projects on both sites are stale, but RAA
has had much longer to gather stale projects. On RubyForge it’s usually a
matter of not having got underway yet.
In the future we may see some cyber-squatting at -forge whereby someone
registers a cool project name, sits on it and sells it to the highest
bidder when somebody actually wants to implement it
Gavin
···
On Tue, Dec 09, 2003 at 06:53:42AM +0900, Gavin Sinclair wrote:
What’s the relationship between that and the RAA?
I don’t really understand your question.
It’s just that, if I’m looking to see if some bit of functionality has
already been turned into a Ruby module, I look on the RAA.
So I was wondering if RubyForge was another place I have to look,
or if the stuff on RubyForge was linked on the RAA, or what.
(?=\d) is a lookahead assertion that checks to see if there’s a digit
ahead of the current pattern without capturing it (which is the
important thing).
Apparently I hid my try pretty well in my reply
Peter
hits forehead
Because of the “>” in irb(main):…:…>, my mua displays it as a comment. continues to hit forehead
Greg ‘blind’ Millam
both your solutions work fine if the number of decimals is less than
or equal to three. What if I would like more precision than that in my
output? Eg.
And that’s a very good question indeed. They [raa and rubyforge]
are not automatically linked. Whether they will be at some point in
the future is a matter for discussion.
Rubyforge has an RSS feed with a list of all projects. RAA could use
that.
At the moment, it’s best to keep both sites in mind when looking
for stuff.
German edition of FAQ on this group now has an additional section
(presently uploading):
···
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
3.3 Wie finde ich Ruby-Software?
Die wichtigsten Adressen für Ruby-Software sind:
Ruby Application Archive (RAA)
RubyForge
Wenn Sie dort keine passende Software finden, sollten Sie zunächst
bei FreshMeat Station machen. Sollen Sie dort ebenfalls nicht fündig
werden, bleibt Ihnen noch die Suche mit Hilfe von Google.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
RAA, RubyForge, FreshMeat and Google are hyperlinked to the obvious
targets. I suggest adding something like that to the english edition,
too:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Where to find Ruby software?
The most important addresses for Ruby software are:
Ruby Application Archive (RAA)
RubyForge
If the don’t have any software that fits you needs you should first
go to FreshMeat. If they also don’t have any fitting software you
still can use Google.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
In the future we may see some cyber-squatting at -forge whereby
someone registers a cool project name, sits on it and sells it to
the highest bidder when somebody actually wants to implement it
A suggestion in analogy to German Markengesetz (law on trademarks).
According to that law a trademark must be ‘used’ within a certain
period of time or there is no legal protection anymore.
I think that if a registered project is not able to upload some web
pages nor some software within three months the one who did
initialize this project should be contacted and given an additional
month to provide something. Four months should be enough to at least
provide some web pages that in some detail explain what the software
will be good for.
After four months the project should be removed.
I think that is fair because I find it very annoying to see
announcements for interesting software and after several months still
not seeing any progress.
IMHO it is a bad habit to register a project if one has nothing to
provide so far. It need not be a usable version of the softwaer but
it should be at least a sketch of what it does and how - Planning
status that is.
The original poster specifically wanted rounding to the nearest
…01, as is normal when formatting amounts currency. When there
might be three or more digits after the decimal point the solution
is slightly more complex, especially since most people don’t want
commas to the right of the decimal point, but might want to see
spaces there. This is where Numeric#format_s in the extensions
library comes in handy.
It’s common when formatting individual numbers in running text (as opposed to
columns of numbers in a table etc.) not to put the separators on either
side of the decimal if there are only four digits: 12,345.678 90
but 1234.5678. An option to handle that in format_s would be nice . . .
-Mark
···
On Tue, Dec 09, 2003 at 05:19:41AM -0800, saggmannen wrote:
both your solutions work fine if the number of decimals is less than
or equal to three. What if I would like more precision than that in my
output? Eg.
I think that if a registered project is not able to upload some web
pages nor some software within three months the one who did
initialize this project should be contacted and given an additional
month to provide something. Four months should be enough to at least
provide some web pages that in some detail explain what the software
will be good for.
After four months the project should be removed.
Yeah, Rich and I should sort that out. The thing is that it’s hard for
me to get motivated to delete inactive projects since they don’t use
hardly any resources - just a few hundred bytes in the Postgres
database.
Yours,
Tom
···
On Tue, 2003-12-09 at 19:03, Josef ‘Jupp’ SCHUGT wrote:
I think that if a registered project is not able to upload some web
pages nor some software within three months the one who did
initialize this project should be contacted and given an additional
month to provide something. Four months should be enough to at least
provide some web pages that in some detail explain what the software
will be good for.
After four months the project should be removed.
Yeah, Rich and I should sort that out. The thing is that it’s hard for
me to get motivated to delete inactive projects since they don’t use
hardly any resources - just a few hundred bytes in the Postgres
database.
Well, maybe they could be marked inactive in some way. When they
appeared in a list, they could be flagged with a little icon, and
when the page is visited, it could have a big red warning at the
top.
Hm, that’s an good idea. Might be a tricky bit trying to figure out
what makes a project inactive, though… lack of CVS commits? Lack of
page views or downloads? Dunno.
Yours,
Tom
···
On Wed, 2003-12-10 at 12:15, Hal Fulton wrote:
Well, maybe they could be marked inactive in some way. When they
appeared in a list, they could be flagged with a little icon, and
when the page is visited, it could have a big red warning at the
top.