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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:21:02+00:00 2026-05-25T15:21:02+00:00

All, I have a set decimal values in C#. I am writing these to

  • 0

All,

I have a set decimal values in C#. I am writing these to fields in a class then serialising this class to an XML data file. However, I have an issue when trying to round a value that is stored as zero or 0, to four decimal places. I want 0 to be stored as 0.0000. Is this possible using decimal? Of course I can do this without issue when casting to string, and this is not the problem. I have read many threads but none seem to address this issue.

Any help would be most appreciated. The code snippit I have is:

// directCost (dCost).
decimal dCost = Convert.ToDecimal(EpiCostValues[(int)epiCostField.directCost]);
dCost = decimal.Round(dCost, 4, MidpointRounding.AwayFromZero);
episodeCostTmp.dCost = dCost;

// indirectCost (iCost).
decimal iCost = Convert.ToDecimal(EpiCostValues[(int)epiCostField.indirectCost]);
iCost = decimal.Round(iCost, 4, MidpointRounding.AwayFromZero);
episodeCostTmp.iCost = iCost;

But this does not force 0 to 0.0000, which is a problem for the required format of the .xml data file.

  • 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-25T15:21:03+00:00Added an answer on May 25, 2026 at 3:21 pm

    Add this line into your code

    dCost *= 1.0000m;
    

    For Eg:

    // directCost (dCost).
    decimal dCost = Convert.ToDecimal(EpiCostValues[(int)epiCostField.directCost]);
    dCost *= 1.0000m;
    dCost = decimal.Round(dCost, 4, MidpointRounding.AwayFromZero);
    episodeCostTmp.dCost = dCost;
    

    Hope this Helps 🙂

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

Sidebar

Related Questions

I have set up multiple targets in a single xml file. I expect all
I have a set of data points in 3D space which apparently all fall
I want to get all fields that have null values but i aint even
My (MySQL) tables have columns with currency values set as Decimal(10,2) with decimals separated
I have Visual Studio 2003 project and I have set all of the AssemblyInfo
I have set up my website to use ASP.NET Membership. it all works fine
I'm sure we all have received the wonderfully vague Object reference not set to
If have a set of classes that all implement an interface. interface IMyinterface<T> {
I have all php tools set up for Jenkins php projects. I set up
I have been set a challenge to create an indexer that takes all words

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.