Quantcast
Channel: Visual COBOL - Forum - Recent Threads
Viewing all articles
Browse latest Browse all 4356

Error_StringToDecimalParse

$
0
0

Hi,

When converting a string to decimal number the result displayed is wrong. Attached the source.
Anyone know how to resolve this problem?

      $set sourceformat"free"
 program-id. Program1 as "ConsoleApplication1.Program1".
 environment division.
 data division.
 working-storage section.
 01 ws-str1 string value "1234.12".
 01 ws-alpha1 pic x(20) value "1234.12".
 01 ws-number pic +9(5).99.
 01 ws-decimal decimal.
 procedure division.
***** Old School COBOL (ANSI85 Intrinsic Function)
     move function numval(ws-alpha1) to ws-number
     display "Number = " ws-number
***** Use .Net to do the same. The Parse Method is available on
***** the numeric data classes.
     move decimal::Parse(ws-str1) to ws-number  *> HERE ws-number = (+23412.00) when it should be (+1234.12)
     display "Number from .Net = " ws-number
***** Use the TryParse Method (Allows you to trap invalid numerics)
     if not decimal::TryParse(ws-str1 , ws-decimal)
     display "Wrong"
     end-if
     display "Decimal = " ws-decimal
     move ws-decimal to ws-number
     display "Number = " ws-number
***** Show an Invalid
     set ws-str1 to "DuffNumber"
     if not decimal::TryParse(ws-str1 , ws-decimal)
     display "Wrong"
     end-if
     stop "Press Return to Terminate"   
     goback
 end program Program1.

Microsoft Visual Studio 2015 Community
Version 14.0.24720.00 Update 1
Microsoft .NET Framework
Version 4.6.01038
Micro Focus Visual COBOL 2.3 Version 2.3.00343.


Viewing all articles
Browse latest Browse all 4356

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>