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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:50:26+00:00 2026-05-24T00:50:26+00:00

I have a calculation for example 2/4 = 0.5, except I can’t find a

  • 0

I have a calculation for example 2/4 = 0.5, except I can’t find a data type that will store this value! Every time I make the calculation it says 0.

Anyone have any suggestions?

  • 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-24T00:50:26+00:00Added an answer on May 24, 2026 at 12:50 am

    Either double or decimal will work fine.

    However, if you just write:

    // Wrong
    double x = 2 / 4;
    

    then it will still use integer division – because both of the operands for the division operator are of type int.

    You can either cast either or both of the operands to double, or use a double literal for either or both of them:

    // Any of these...
    double x = (double) 2 / 4;
    double x = 2 / (double) 4;
    double x = (double) 2 / (double) 4;
    double x = 2.0 / 4;
    double x = 2 / 4.0;
    double x = 2.0 / 4.0;
    double x = 2d / 4;
    double x = 2 / 4d;
    double x = 2d / 4d;
    

    Note that both double and decimal are floating point types. They don’t represent arbitrary rational numbers (fractions). For example, neither can accurately represent 1/3. If you need a rational number type, you’ll have to write your own or look for a third party implementation.

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

Sidebar

Related Questions

I have a calculation that goes something like this: Price = value * randomNumberBetween(decimalValueA,
I have a calculation that generates what appears to be the Float 22.23, and
I have some idea that it is due to some complex calculation, but i
I have a SQL statement (MS SQL Server 2005) that does a simple calculation
I have a method, which uses random samples to approximate a calculation. This method
i have to build some financial data report, and for making the calculation, there
I have the following data (I have a lot more rows this is just
From a blog: The basic idea with CSS expressions is that you will have
I have picked up this example which converts BitSet to Byte array. public static
i have a bunch of data collection , example : 1.00 3 4 1.00

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.