Hello,
I am trying to display the value of a data item in a textbox in a managed COBOL program.
The variable is defined
01 DecimalValue PIC S9(5)V99
and contains the value 99.00.
When I put that value into a textbox
set textBox1::Text to DecimalValue::ToString()
it displays as 9900.
I tried
set textBox1::Text to DecimalValue::ToString("N2")
to get two decimal places but that just turned it into 9900.00.
Now I am a C# developer and know little about COBOL but I think I know why this is happening; the V is a virtual decimal point and not really there at all. I assume in a native COBOL language like AcuCOBOL the V gets replaced with a "." when the value is displayed but in .NET this doesn't take place and the value is always seen as 9900. Then the ToString("N2") method adds a ".00" to it. This is, of course, not what I want.
So my question is how to get the value into the textbox formatted the way the pic clause is defined?
If I assign the value to a .NET Double data type then pass THAT value to the textbox, it works:
declare temp as type Double = DecimalValue.
set textBox::Text to temp::ToString("N2").
Now I get 99.00 like it should be. So then I tried putting the variable inside parenthesis which SHOULD force the compiler to evaluate the variable as if it were being assigned BEFORE evexuting the ToString method. This method is used in most languages to force the compiler to evaluate things in a specific order.
set textBox1::Text to (DecimalValue)::ToString("N2")
Sadly, it doesn't work here. Shouldn't it though?
Eventually I came up with this:
set textBox1::Text to type Convert::ToDouble(DecimalValue)::ToString("N2").
which works.
But I'd like to know if there is a more straightforward way to do this and also why doesn't enclosing the data item in parenthesis work.
Thank you.
#textboxformatnumeric