Hi.

I just tested the regexp against 19.0000 and it works, but I got a
little problem with the [\s\n]I just solved:

s = '19.0000 / 482.600 mm / 19.060000 / 482.600 mm'
s.gsub!(/(\.0?[^0])?0+/, '\1').gsub!(/\.([\s\n])/, '\1')

This produces: '19 / 482.6 mm / 19.06 / 482.6 mm'

The "insignificant" trailing zeros after are always trimmed after a
decimal point.

Pepe

On Feb 28, 6:30 pm, Matt Jones <[email protected]> wrote:
> There appear to be some good solutions here, but I thought I'd jump
> in
> with a bit of non-Rails technical detail.
>
> I'd double check with the source of this data - the zeros may be
> significant.
> (seehttp://en.wikipedia.org/wiki/Significant_figures)
>
> The data given doesn't seem to match that (482.600 mm would be written
> as
> 19.0000"), but it doesn't hurt to verify...
>
> --Matt Jones
>
> On Feb 27, 2:47 pm, northband <[email protected]> wrote:
>
> > Hi -
>
> > I would like to use gsub() to strip decimals with trailing zeros from
> > a string.  My string looks like this:
> > --
> > 19.0 " / 482.600 mm
> > --
>
> > I would like to end up with this:
> > --
> > 19 " / 482.6 mm
> > --
>
> > Anyone have a regular expression that can do this?
>
> > Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to