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

Related Questions

Suppose you have a system on the other side of a network that sends
Suppose that we have following tables create table Employee( 2 EMPNO NUMBER(3), 3 ENAME
Suppose that I have a request handler that accepts an argument: key And let
Let's suppose I have a Winforms app with a Dictionary that looks like this:
Suppose that... I have a complex XML schema, one that imports/includes other schema files,
Suppose that I have a database with student information: {'student_name' : 'Alen', 'subjects' :
Suppose that you have a function f: List a -> a such that f
Suppose that I have a 2D array (matrix) in Java like this... int[][] MyMat
Suppose that we have file like this: sometext11 sometext12 sometext13 sometext21 sometext22 sometext23 Texts
Suppose that you have a bunch of projects in your Eclipse workspace. Some are

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.