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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:44:37+00:00 2026-05-23T10:44:37+00:00

I have a bunch of numeric values. They can be Short , Integer ,

  • 0

I have a bunch of numeric values. They can be Short, Integer, Long, Float or Double (and are the output of an external library (snakeYaml) which returns these as type Object)

I’d like to convert these Objects (which are guaranteed to be Numbers) to Double values in my program. (Storage space is not an issue).

The Java compiler obviously throws a ClassCastException when attempting to cast from an object which is actually an Short/Integer/Long/Float to a Double.

Any hints as to the most efficient method to adopt would be gratefully acknowledged.

  • 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-23T10:44:38+00:00Added an answer on May 23, 2026 at 10:44 am

    They can be Short, Integer, Long, Float or Double

    These classes are all subclasses of the Number class, which means that you can always use the Number.doubleValue method.

    Example:

    Number[] nums = { new Double(1.2), new Integer(5), new Float(3.0) };
    
    double num1 = nums[0].doubleValue();
    double num2 = nums[1].doubleValue();
    double num3 = nums[2].doubleValue();
    

    or, if you really want Double values, you can rely on autoboxing and simply do:

    Double num1 = nums[0].doubleValue();
    Double num2 = nums[1].doubleValue();
    Double num3 = nums[2].doubleValue();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of text inputs with numeric values: <input type='text' value='25' />
I have bunch of Symbol MC 70 devices. They run Windows Mobile 5. Most
I've been trying to write an extend function so I can have bunch of
I have a bunch of numeric stats data gathered over time. I need to
We have bunch of Domain Entities which should be rendered to an html format,
week DKK id=radio2 value=75 /> I have bunch of these div entry generated by
Does Java and/or Spring have the concept of properties? I have bunch of domain
I have a bunch of files that I need to be able to transport
I have a bunch of latitude/longitude pairs that map to known x/y coordinates on
I have a bunch of .NET frameworks installed on my machine. I know that

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.