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

  • Home
  • SEARCH
  • 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 6345273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:47:29+00:00 2026-05-24T20:47:29+00:00

I have example this number: 5032 I want to get this: 5.0.32 How can

  • 0

I have example this number: 5032

I want to get this: 5.0.32

How can I do this with ruby string manipulation?

  • 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-24T20:47:29+00:00Added an answer on May 24, 2026 at 8:47 pm

    I’d be curious to hear the pros and cons of these different solutions. What’s the fastest ? What’s the clearest ? Are regular expressions expensive ?

    Here’s yet another solution:

    sprintf("%s.%s.%s%s", *5032.to_s.split(""))
    

    Here’s our results. Mine is slowest:

    require 'benchmark'
    
    n = 500000
    Benchmark.bm do |x|
      x.report { n.times {"5032".sub(/^(.)(.)/,"\\1.\\2.")}}
      x.report { n.times {"5032".insert(2, ".").insert(1, ".")}}
      x.report { n.times {sprintf("%s.%s.%s%s", *5032.to_s.split("")) }}
    end
    
    
    
         user     system      total        real
      0.610000   0.000000   0.610000 (  0.607663)
      0.320000   0.000000   0.320000 (  0.325050)
      3.030000   0.000000   3.030000 (  3.029342)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have this number 0601811002 and I want cut the number. Example
I have for example this string: iCanSeeBluePeople and I need it to separate it
I have for example this array (each number is singolar, no one duplicate) called
Say I have this example string <td><a href=/one-two-three/menus title=test</td> <td><a href=/one-two-three/menus/13:00 title=test</td> <td><a href=/one-two-three/schedule/could
If I have say for example 100,000 rows to insert/update/delete, and this number will
I have an object which looks for example like this Name Number ---- ------
I have a series of binary number sequences as indicator variables. For example this
I have, for example this number list: [1,2,3,4,5,6,7,8,9,10]. I have to search a number
I have this for example: 0 10000101 00111100000000000000000 and want to convert this to
I have this example FactoryGirl.define do @site = FactoryGirl.create(:my_site) factory :user do email {

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.