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

The Archive Base Latest Questions

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

I am using the following to put decimal places when formatting an amount but

  • 0

I am using the following to put decimal places when formatting an amount but I am not getting the correct amount when testing with eg 25000 I am expecting 25000.00
but I am getting 25000.

What I am doing wrong?How should I change it?

                [TestCase(123.45453, 123.45, 2)]
                [TestCase(125.55453, 125.55, 2)]
                [TestCase(125.55653, 125.56, 2)]
                [TestCase(125.56554, 125.57, 2)]
                [TestCase(25000,25000.00,2)]

  public void MyRoundFunction_returns_amount_with_decimal_places(decimal amountToTest, decimal expected, int decimalPlaces)
                {
                    decimal actual = MyRoundFunction(amountToTest, MidpointRounding.ToEven, decimalPlaces);
                    Assert.AreEqual(expected, actual);
                }


         public static decimal MyRoundFunction(decimal value, MidpointRounding midpointRounding, int decimalPlaces)
                {
                    return Math.Round(value, decimalPlaces, midpointRounding);
                }

EDITED:

If you were to format a decimal value whatever the amount would always have 2 decimal even when is something like 25000 and you want 25000.00 or 1234.224543 returns 1234.22 how would you code it?

  • 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-25T06:21:28+00:00Added an answer on May 25, 2026 at 6:21 am

    It looks to me like you’re passing in double values instead of decimals. Try this:

    [TestCase(123.45453m, 123.45m, 2)]
    [TestCase(125.55453m, 125.55m, 2)]
    [TestCase(125.55653m, 125.56m, 2)]
    [TestCase(125.56554m, 125.57m, 2)]
    [TestCase(25000m, 25000.00m,2)]
    

    It’s possible that that won’t even build – I wouldn’t be surprised if decimal values were disallowed in attributes as the CLR doesn’t know about them. If that does happen, you probably want to change the input to strings, parse them to decimals at the start of the test, and then compare them. You’ll need to check that decimal.Parse preserves the trailing digits, of course… I think it does, but I can’t remember for sure offhand.

    Others have pointed out the “only round at the point of display, when you convert to a string” possibility – I can’t say whether or not that’s appropriate in your case. I know that there is a difference in representation between 25000m and 25000.00m. Whether you should be rounding to a given number of decimals will depend on your business requirements, of course.

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

Sidebar

Related Questions

I am using the following code, UIManager.put(JFrame.activeTitleBackground, Color.red); for change the toolbar color in
I put some colored text to my rich text box my using the following
i am using following code to make an httpPost call but it is returning
I'm using the following function to put each facility node of my XML in
The following field is meant to format money as a two places decimal (quantized).
I put a Ajax link using the following code: echo chtml::ajaxLink('GO', 'http://localhost/index.php?r=user/delete', array('method'=>'POST')); But,
I am using following PHP code to connect to MS Access database: $odb_conn =
I am using following storedprocedure set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO Alter PROCEDURE
I am using following code in rowdatabound function. Protected Sub gvwMileStone_RowDataBound(ByVal sender As System.Object,
I'm using following peace of code to output an array: echo ======output without array_unique=====;

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.