Highlighted
Alex_Castro Respected Contributor.
Respected Contributor.
82 views

Formatting Numeric Data from Text Boxes WinForm

Jump to solution

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?

 

0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

Re: Formatting Numeric Data from Text Boxes WinForm

Jump to solution

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

0 Likes
2 Replies
Micro Focus Expert
Micro Focus Expert

Re: Formatting Numeric Data from Text Boxes WinForm

Jump to solution

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

0 Likes
Alex_Castro Respected Contributor.
Respected Contributor.

Re: Formatting Numeric Data from Text Boxes WinForm

Jump to solution

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. 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.