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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:39:09+00:00 2026-05-11T15:39:09+00:00

Suppose that we have a System.Decimal number. For illustration, let’s take one whose ToString()

  • 0

Suppose that we have a System.Decimal number.

For illustration, let’s take one whose ToString() representation is as follows:

d.ToString() = '123.4500' 

The following can be said about this Decimal. For our purposes here, scale is defined as the number of digits to the right of the decimal point. Effective scale is similar but ignores any trailing zeros that occur in the fractional part. (In other words, these parameters are defined like SQL decimals plus some additional parameters to account for the System.Decimal concept of trailing zeros in the fractional part.)

  • Precision: 7
  • Scale: 4
  • EffectivePrecision: 5
  • EffectiveScale: 2

Given an arbitrary System.Decimal, how can I compute all four of these parameters efficiently and without converting to a String and examining the String? The solution probably requires Decimal.GetBits.

Some more examples:

Examples Precision  Scale  EffectivePrecision  EffectiveScale 0        1 (?)      0      1 (?)               0 0.0      2 (?)      1      1 (?)               0 12.45    4          2      4                   2 12.4500  6          4      4                   2 770      3          0      3                   0 

(?) Alternatively interpreting these precisions as zero would be fine.

  • 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. 2026-05-11T15:39:10+00:00Added an answer on May 11, 2026 at 3:39 pm

    Yes, you’d need to use Decimal.GetBits. Unfortunately, you then have to work with a 96-bit integer, and there are no simple integer type in .NET which copes with 96 bits. On the other hand, it’s possible that you could use Decimal itself…

    Here’s some code which produces the same numbers as your examples. Hope you find it useful 🙂

    using System;  public class Test {     static public void Main(string[] x)     {         ShowInfo(123.4500m);         ShowInfo(0m);         ShowInfo(0.0m);         ShowInfo(12.45m);         ShowInfo(12.4500m);         ShowInfo(770m);     }      static void ShowInfo(decimal dec)     {         // We want the integer parts as uint         // C# doesn't permit int[] to uint[] conversion,         // but .NET does. This is somewhat evil...         uint[] bits = (uint[])(object)decimal.GetBits(dec);           decimal mantissa =              (bits[2] * 4294967296m * 4294967296m) +             (bits[1] * 4294967296m) +             bits[0];          uint scale = (bits[3] >> 16) & 31;          // Precision: number of times we can divide         // by 10 before we get to 0                 uint precision = 0;         if (dec != 0m)         {             for (decimal tmp = mantissa; tmp >= 1; tmp /= 10)             {                 precision++;             }         }         else         {             // Handle zero differently. It's odd.             precision = scale + 1;         }          uint trailingZeros = 0;         for (decimal tmp = mantissa;              tmp % 10m == 0 && trailingZeros < scale;              tmp /= 10)         {             trailingZeros++;         }          Console.WriteLine('Example: {0}', dec);         Console.WriteLine('Precision: {0}', precision);         Console.WriteLine('Scale: {0}', scale);         Console.WriteLine('EffectivePrecision: {0}',                           precision - trailingZeros);         Console.WriteLine('EffectiveScale: {0}', scale - trailingZeros);         Console.WriteLine();     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Instead of using a navigation controller, I would just move… May 12, 2026 at 1:02 am
  • Editorial Team
    Editorial Team added an answer Very well you can access the Controls in the Master… May 12, 2026 at 1:02 am
  • Editorial Team
    Editorial Team added an answer Can you give more details about how you are initiating… May 12, 2026 at 1:02 am

Related Questions

Suppose that we have a System.Decimal number. For illustration, let's take one whose ToString()
I am looking for a good source control solution. Here are the requirements: Must
I want to ask a question about how you would approach a simple object-oriented
So, I work in a fairly small IT section. We have a trouble ticketing
We all know the observer pattern : You have a subject which is able

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.