Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Forced decimal point in C#


Recommended Posts

  • 2 weeks later...

3rd String,

 

Try this...

 

See Custom Numeric Format Strings for reference.

 

code:

       using System.Globalization;        

 

private NumberFormatInfo nfi = new CultureInfo(CultureInfo.CurrentCulture.Name).NumberFormat;

 

/// <summary>

/// Formats the supplied (double) value to a string.

/// Output always contains the NumberDecimalSeparator for the current Culture.

/// </summary>

/// <param name="value"></param>

/// <returns>A string containing the formatted value</returns>

private string FormatValue(double value)

{

string str = value.ToString("#.####;;0");

if (str.Contains(nfi.NumberDecimalSeparator) == false)

{ str += nfi.NumberDecimalSeparator; }

return str;

}

Link to comment
Share on other sites

Thanks Roger

 

I like what you did bieng culturaly aware. This was for a small program for my companies personal use so I never even thought about the different decimal seporators.

 

This is what I had that worked.

 

code:

 

private string formatOutput (double i)

{

int i2 = (int)i;

return ((double)i2 == i) ? (i.ToString() + ".") : i.ToString();

}


When I get time I'm gonna go back & try to incorporate your method.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...