Solved

DataFormatString: how to include padding zeros?

Posted on 2004-04-13
2
1,951 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

13 Experts available now in Live!

Get 1:1 Help Now