Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7180169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:17:30+00:00 2026-05-28T17:17:30+00:00

Right now I’m building a small app that imports data from a spreadsheet and

  • 0

Right now I’m building a small app that imports data from a spreadsheet and due to the nature of the original entry, there is a string being read in that has values such as 8½, 2½, etc.

My goal with a simple function is to convert 2½ into float 2.5, for example.

I’ve tried the .to_f method but that has left me with a weird value of 2.02½.

Any insight or suggestions here would be very much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:17:31+00:00Added an answer on May 28, 2026 at 5:17 pm

    Unicode only supports a small number of vulgar fractions so a simple lookup table will do the trick:

    # You might want to double check this mapping
    vulgar_to_float = {
        "\u00BC" => 1.0 / 4.0,
        "\u00BD" => 1.0 / 2.0,
        "\u00BE" => 3.0 / 4.0,
        "\u2150" => 1.0 / 7.0,
        "\u2151" => 1.0 / 9.0,
        "\u2152" => 1.0 /10.0,
        "\u2153" => 1.0 / 3.0,
        "\u2154" => 2.0 / 3.0,
        "\u2155" => 1.0 / 5.0,
        "\u2156" => 2.0 / 5.0,
        "\u2157" => 3.0 / 5.0,
        "\u2158" => 4.0 / 5.0,
        "\u2159" => 1.0 / 6.0,
        "\u215A" => 5.0 / 6.0,
        "\u215B" => 1.0 / 8.0,
        "\u215C" => 3.0 / 8.0,
        "\u215D" => 5.0 / 8.0,
        "\u215E" => 7.0 / 8.0,
        "\u2189" => 0.0 / 3.0,
    }
    

    Then, a little bit of regex wrangling to pull your “number” apart:

    s = "2½"
    _, int_part, vulgar_part = *s.match(/(\d+)?(\D+)?/)
    

    And finally, put them together taking care to properly deal with possible nils from the regex:

    float_version = int_part.to_i + vulgar_to_float[vulgar_part].to_f
    

    Remember that nil.to_i is 0 and nil.to_f is 0.0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now, I'm particularly interested in reading the data from MP3 files (ID3 tags?),
Right now, I have a jQuery UI pop-up dialog that reads from an external
Right now, I keep all of my projects on my laptop. I'm thinking that
Right now I have an SSIS package that runs every morning and gives me
Right now, I have code that looks something like this: Private Sub ShowReport(ByVal reportName
Right now, I have configuration setting for morphia talks to one MongoDB from Play!.
Right now we have a dll file that contains all the database calls and
Right now I have a script that creates symlinks to anything newer than 2
Right now the library can translate this operation Select * from List where name
Right now a lot of my applications use GWT-RPC for retrieving POJO's from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.