?
Solved

Rounding the Double Variables

Posted on 2005-05-09
3
Medium Priority
?
1,336 Views
Last Modified: 2008-01-09
Hi,

I am using the following to round the double number:

double amount = 12.565;
Console.WriteLine(amount.ToString("0.00"));

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.
0
Comment
Question by:nauman_ahmed
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
Ramuncikas earned 1000 total points
ID: 13962226
Hey, Nauman.

If I were you, I'd use this:

Console.WriteLine(amount.ToString("#,##0.000"));

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.
Ramuncikas
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13967691
Console.WriteLine(amount.ToString("N2"));

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

Assisted Solution

by:b1xml2
b1xml2 earned 1000 total points
ID: 13967694
if you do not want the commas, then what you have placed is sufficient.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

807 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