Page 1 of 1

String Format Specifier

Posted: Fri Sep 21, 2012 12:59 pm
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;

Re: String Format Specifier

Posted: Fri Sep 21, 2012 1:41 pm
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;
		}

Re: String Format Specifier

Posted: Fri Sep 21, 2012 2:23 pm
by MarkTX
Working great now, thanks