Rounding the Double Variables

Posted on 2005-05-09
Last Modified: 2008-01-09

I am using the following to round the double number:

double amount = 12.565;

The rounded amount will then be sent to the payment gateway for further order processing.  I just want to know if the above segment is fine or I should try something else.

Thanks, Nauman.
Question by:nauman_ahmed
    LVL 14

    Accepted Solution

    Hey, Nauman.

    If I were you, I'd use this:


    I'd use three decimal places because in case of discounts or other rounding efect the number can have three and even more decimal digits. But it's a case when YOU have to decide. And you should learn what type and format of data payment gateway accepts.

    On the other hand, if two decimal places are enouth, then it's enough and in that case your formatting string is good.

    Hope this will help.
    LVL 23

    Expert Comment


    That will provide the appropriate commas and two decimal places.
    LVL 23

    Assisted Solution

    if you do not want the commas, then what you have placed is sufficient.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now