Formatting Numeric Data from Text Boxes WinForm

I spend three days trying to solve this last week and was unsuccessful. I currently have a Windows Form text box in which the user types the numbers 123456789. I want to move that data into a numeric field with the value of: 1234567.89 where the last two numbers are to be placed to the right of the decimal point. What I have is the following:

working-storage section.

01 TOTAL-BALANCE 9(7)V99.

method-id txt-TOTAL-BALANCE_Text_Changed final private.
procedure division using by value sender as object e as type System.EventArgs.

set TOTAL-BALANCE  to binary-double unsigned::Parse(txt-TOTAL-BALANCE::Text)

end method.

The above command, however, gives me a TOTAL-BALANCE  with a value of 123456789.00. I have tried a couple of ways of getting the last two digits in the decimal places but I cannot seem to be successful. I was reading a similar thread located at :https://community.microfocus.com/t5/Visual-COBOL-Forum/Formatting-numeric-data-items/m-p/1731883.

I tried some of the suggestion in this thread but could not get my code to compile. What I basically want to do is to convert a string to a numeric decimal. Is there an easier way to do this?

 

  • Verified Answer

    I would think that the result would actually be 3456789.00 because it is a pic 9(7) so the results would be truncated.

    You could divide the result by 100?

    set TOTAL-BALANCE  to binary-double unsigned::Parse(txt-TOTAL-BALANCE::Text) / 100

  • Yes, it was truncating the first two numbers. Your solution worked, thank you! The field  TOTAL-BALANCE will be used for calculating other transactions so I want to make sure that even though the text box is a text string that the string that was passed to the  TOTAL-BALANCE field  will nevertheless be a numeric field. I will assume that that is the case since I have defined TOTAL-BALANCE as a numeric field.