Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Convert fraction to decimal
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Psyclone  
View profile  
 More options Jun 15 2009, 4:54 pm
From: Psyclone <jaengl...@gmail.com>
Date: Mon, 15 Jun 2009 13:54:35 -0700 (PDT)
Local: Mon, Jun 15 2009 4:54 pm
Subject: Convert fraction to decimal
Hey, all. Need some help here.

I have a working PHP script to convert a fraction to a decimal using a
regular expression. The PHP works, but the regex is broken somehow.
Here's what I have:

([0-9]+)?[[:space:]]?(([0-9]+)/([0-9]+))?

The PHP extrapolates this into a base variable, numerator, and
denominator.

So it works if I have 1 1/2, or 2/3. But if I have something like
50/200, it assumes that I mean 5 0/200. I get why it's doing that. I
have a ? next to the space. I've tried doing (([0-9]+)?[[:space:]])?
but that breaks the whole thing and gives me 1's and 0's. Am I on the
right track, here?

I am just not a regexpert, so I need a little push in the right
direction.

Thanks for your time!


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
J. Allen R. Day  
View profile  
 More options Jun 16 2009, 8:09 am
From: "J. Allen R. Day" <cr...@jarday.com>
Date: Tue, 16 Jun 2009 07:09:45 -0500
Local: Tues, Jun 16 2009 8:09 am
Subject: Re: Convert fraction to decimal

On Mon, Jun 15, 2009 at 3:54 PM, Psyclone<jaengl...@gmail.com> wrote:
> ([0-9]+)?[[:space:]]?(([0-9]+)/([0-9]+))?

Try this:
(?:([0-9]+)[[:space:]])?(([0-9]+)/([0-9]+))?

It only finds a whole number if the space delimiter is present, rather
than filling as many groups as possible.

A

--
Remember, no matter where you go, there you are. -Buckaroo Banzai


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google