String Format Specifier

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
MarkTX
Posts: 9
Joined: Fri Dec 30, 2011 11:03 am

String Format Specifier

Post by MarkTX »

Hello,

I have a tag of data type FLOAT. I want to convert the tag value to a string with two decimal places of precision. For example, value 10.12345678 would be converted to "10.12". This is what I am using:

String s = String.Format("{0:0.00}", Globals.Tags.DischargeRate.Value);

However, s does does not become "10.12", instead it becomes "10.123456". I have also tried:

String s = String.Format("F3", Globals.Tags.DischargeRate.Value);

with the same result. How to accomplish this? I am using A12 and iX 2.0;

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: String Format Specifier

Post by mark.monroe »

Standard Numeric Format Strings.

Code: Select all

		void Button1_Click(System.Object sender, System.EventArgs e)
		{
			Globals.Tags.Tag1.Value = 12.12344;
			String s = Globals.Tags.Tag1.Value.Double.ToString("F2");
			this.Text1.Text = s;
		}
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

MarkTX
Posts: 9
Joined: Fri Dec 30, 2011 11:03 am

Re: String Format Specifier

Post by MarkTX »

Working great now, thanks

Post Reply