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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:38:22+00:00 2026-05-18T08:38:22+00:00

From a XML file I receive decimals on the format: 1.132000 6.000000 Currently I

  • 0

From a XML file I receive decimals on the format:

1.132000
6.000000

Currently I am using Decimal.Parse like this:

decimal myDecimal = Decimal.Parse(node.Element("myElementName").Value, System.Globalization.CultureInfo.InvariantCulture);
  • How do print myDecimal to string
    to look like below ?

    1.132
    6
    
  • 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-18T08:38:23+00:00Added an answer on May 18, 2026 at 8:38 am

    I don’t think there are any standard numeric format strings which will always omit trailing insignificant zeroes, I’m afraid.

    You could try to write your own decimal normalization method, but it could be quite tricky. With the BigInteger class from .NET 4 it would be reasonably feasible, but without that (or something similar) it would be very hard indeed.

    EDIT: Okay, I think this is what you want:

    using System;
    using System.Numerics;
    
    public static class DecimalExtensions
    {
        // Avoiding implicit conversions just for clarity
        private static readonly BigInteger Ten = new BigInteger(10);
        private static readonly BigInteger UInt32Mask = new BigInteger(0xffffffffU);
    
        public static decimal Normalize(this decimal input)
        {
            unchecked
            {
                int[] bits = decimal.GetBits(input);
                BigInteger mantissa = 
                    new BigInteger((uint) bits[0]) +
                    (new BigInteger((uint) bits[1]) << 32) +
                    (new BigInteger((uint) bits[2]) << 64);
    
                int sign = bits[3] & int.MinValue;            
                int exponent = (bits[3] & 0xff0000) >> 16;
    
                // The loop condition here is ugly, because we want
                // to do both the DivRem part and the exponent check :(
                while (exponent > 0)
                {
                    BigInteger remainder;
                    BigInteger divided = BigInteger.DivRem(mantissa, Ten, out remainder);
                    if (remainder != BigInteger.Zero)
                    {
                        break;
                    }
                    exponent--;
                    mantissa = divided;
                }
                // Okay, now put it all back together again...
                bits[3] = (exponent << 16) | sign;
                // For each 32 bits, convert the bottom 32 bits into a uint (which won't
                // overflow) and then cast to int (which will respect the bits, which
                // is what we want)
                bits[0] = (int) (uint) (mantissa & UInt32Mask);
                mantissa >>= 32;
                bits[1] = (int) (uint) (mantissa & UInt32Mask);
                mantissa >>= 32;
                bits[2] = (int) (uint) (mantissa & UInt32Mask);
    
                return new decimal(bits);
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                Check(6.000m);
                Check(6000m);
                Check(6m);
                Check(60.00m);
                Check(12345.00100m);
                Check(-100.00m);
            }
    
            static void Check(decimal d)
            {
                Console.WriteLine("Before: {0}  -  after: {1}", d, d.Normalize());
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using feedparser for parsing from XML file.But I couldn't parse <geo:lat> ,
I will receive an XML from Server, and have to parse the xml file,
this is my xml file,i do not known how to retrieve value from xml
I am currently trying to read from an xml file which records the jobs
I need to read the content of a XML file that I receive from
I am using NSXmlParser to extract a string from an XML file. The xml
I need to parse a XML file which I get from third party to
I have this form to upload an xml file to server, I am using
Below is the information I receive from DB. It's originally from an XML file,
My XML file looks something like this: <MyXml> <Version> 9.3.2 </Version> <Resources> <Sets> <ItemCollection>

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.