Skip to main content

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

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

Hi

Add this in

01  DecmialValue-E  PIC  ZZ,ZZ9.99-.

then

   MOVE DecimalValue TO DecimalValue-E.

and then work with the 'edited' field DecimalValue-E which will show 4 leading spaces 99.00 and one trailing space for the minus sign to use if the value becomes negative

The Zs in the edit mask will show as spaces unless there is a significant digit to be used

And the comma to demark the thousands will also be blank unless it is needed to be invoked

Once you have created the edited version, your original set textBox1::Text to DecimalValue::ToString() should work OK once adjusted to refer to DecimalValue-E

Note 1: DecimalValue-E will occupy 10 positions - you can count the characters in the 'edit mask'

Note 2: there would be other ways to do this - this is just one simple way


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

Oops!  A slight typo in the above

Use this instead

01  DecimalValue-E  PIC  ZZ,ZZ9.99-


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

Oops!  A slight typo in the above

Use this instead

01  DecimalValue-E  PIC  ZZ,ZZ9.99-


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

Hallo

You mentioned that you are a C# developer. So I recommend using the new Cobol type definitions and not the old Picture. In your case the type is decimal: 01 DecimalValue decimal. See Help for all .Net compatible definitions (string, binary-short, binary-long, decimal …). These types will also be suitable for WPF-Bindings, etc.

Freundliche Grüsse

Werner Lanter


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

If on the other hand you have existing code which uses the PICTURE definition, you should be able to get the results you want by using a cast operation to decimal (which is a predefined type meaning System.Decimal on .NET).  So something like:

01 DecimalValue PIC S9(5)V99

 set textBox1::Text to DecimalValue as decimal::ToString()


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

PIC S9(5)V99 is not a real decimal value, it's just a numeric string. The following statement does what you want:

set textBox1::Text  to  (DecimalValue as decimal)::ToString("N02")

Paramter "N02" will convert with the system culture opposite to numeric-edited in Cobol.