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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:07:35+00:00 2026-06-11T20:07:35+00:00

I have a double and need to convert it to a decimal. If the

  • 0

I have a double and need to convert it to a decimal. If the value is too large/small the result should be decimal.MaxValue/decimal.MinValue. What is the best way to do this?

  • 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-11T20:07:36+00:00Added an answer on June 11, 2026 at 8:07 pm

    I assume you realize this is a lossy conversion, and should be avoided if possible? If you really need it:

    private static readonly double MaxDecimalAsDouble = (double) decimal.MaxValue;
    private static readonly double MinDecimalAsDouble = (double) decimal.MinValue;
    
    ...
    public decimal ConvertWithCap(double input)
    {
        return input >= MaxDecimalAsDouble ? decimal.MaxValue
             : input <= MinDecimalAsDouble ? decimal.MinValue
             : (decimal) input;
    }
    

    This way the cap is checked in terms of the double value, but then return the capped value hard-coded to be the decimal value. This avoids the problem where double can’t accurately represent the max/min values of decimal.

    (Even at the largest scales of decimal, consecutive integers can be represented – but that’s not the case for double.)

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

Sidebar

Related Questions

I have string value in that I need to convert to double in VB.Net.
I have a: DateTime?[] dates I need to convert to: Double?[] oaDates Any way
Need some help with DataFormatString in GridView. I have a Double value that needs
I have some customized string formats of double values. I need to convert these
I have a double whose value is 10,000,000.00 (ten millions). I have to convert
I have to convert values (double/float in C#) to bytes and need some help..
I have a need to convert NSString to double. If this string is in
In our code we have a double that we need to convert to an
I have table which contains double values stored in mysql database ...I need to
I have been developing the application for drawing and I need to detect double

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.