• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1427
  • Last Modified:

C# - controling the number of decimal places on a string which represents a number with decimals and remainder Zeros etc...

Hi everyone,

Just a quick question.  I have a...

string myNum;

This gets filled with quotes like this...

1.2452
1.2000
1.2470

when there viewed in a gui however they look like this...

1.2452
1.2
1.247

if you notice the last quote drops the remainder zero off.  I need to control the number of decimal places shown.

Is there a string or String method which will keep the remainder zero?  something like
myNum(f4); or something easy.  FYI I can't control when the float or double is converted to the string so I have to operate on the sting afterwards.

Let me express my thanks in advance for your help.

Best,
Dynotoe

0
Dynotoe
Asked:
Dynotoe
  • 2
1 Solution
 
Bob LearnedCommented:
Try this:

string test = Decimal.Parse(myNum).ToString("##.0000");

Bob
0
 
DynotoeAuthor Commented:
Hi Bob,

Thanks again!

Cheers,

Dynotoe
0
 
DynotoeAuthor Commented:
Bob does your example limit the integer part to just 2 places via the ##?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now