Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

DataFormatString: how to include padding zeros?

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying 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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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