Solved

DataFormatString: how to include padding zeros?

Posted on 2004-04-13
2
1,961 Views
Last Modified: 2012-05-04
Hi,

which (c#) dataformat string would you choose:

input: 1523.460
current output: 1523.46

Desired output: 1523.460
0
Comment
Question by:Raab314159
2 Comments
 

Author Comment

by:Raab314159
ID: 10812584
REM:

The number is not allowed to have a fixed number of digits! Sometimes, the number may represent temperature, sometimes wavelenght, etc
0
 
LVL 10

Accepted Solution

by:
ptmcomp earned 125 total points
ID: 10813478
If you want the input to be equal to the output use string or save the number of significant digits in a seperate variable.

To format a number with 3 digits after decimal point use: string.Format("{0:#.000}", 1523.46)

In a float / double / decimal there is no information about the number of significant digits. You have to implement it yourself or you might find a 3rd party library which provides this functionality.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
insert value of checklistbox checked 4 38
defining NULL or 0 10 50
How to Generate a Method from a keyboard shortcut in Visual Studio? 2 33
c#, case, if 4 16
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

685 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