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 8787121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:48:24+00:00 2026-06-13T21:48:24+00:00

I have few string values which I am fetching from my database e.g 1/4,2/3

  • 0

I have few string values which I am fetching from my database e.g

"1/4","2/3"

But while displaying as Android ListView contents I need to display it as 0.25,0.66.

Now I don’t want to split the string and then covert to individual strings to numbers and
then divide them to have result.

Does anyone know, any direct functions like Double.valueOf or parseDouble kind?

  • 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-06-13T21:48:25+00:00Added an answer on June 13, 2026 at 9:48 pm

    Why you “dont want to split the string and then covert to individual strings to numbers and then divide them to have result”?

    I am not aware of any built-in function to do that so the simplest solution:

    double parse(String ratio) {
        if (ratio.contains("/")) {
            String[] rat = ratio.split("/");
            return Double.parseDouble(rat[0]) / Double.parseDouble(rat[1]);
        } else {
            return Double.parseDouble(ratio);
        }
    }
    

    It also covers the case where you have integer representation of ratio

    parse("1/2") => 0.5
    parse("3/7") => 0.42857142857142855
    parse("1") => 1.0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string built from a few segments, which are not separated, but
I have a collection of string names, few names starts with X100,x200,x121 which has
I have service in which i am accessing few configuration properties from grailsApplication I
I have a complex adress string, or rather different possible formats, which I need
I have few NSDate objects which contain values compliant to this format yyy-MM-dd'T'HH:mm:ss.SSS When
I have a p:commandButton on click of which I need to add a few
I have a web from that has a few text boxes which are visible
Say I have a few string like Hi my name is <Name> Hi <name>,
I have a ini file which contains some sample values like: [Section1] Value1 =
I have an object which contains quite a few other objects in an IList

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.