hi all,may, what are my options? just for grins, '-7' --> -7 works just fine, so what is it with '+'?
i'm trying to convert a string to an integer. the string is '+7' (43, 55). so i thought Integer fromString: aString would be the answer. not so easy. it fails with an 'Invalid format for Integer' . not sure why it's an invalid format, but be that as it
thanks in advance for help,Integer class>>#readFrom: only ever checks for the existence of negative sign to signify a negative number, not the positive sign to signify a positive number. I guess a number without a positive sign is always considered a positive number and the
john
On Tuesday, 26 October 2021 at 06:00:51 UTC+10, john c wrote:it may, what are my options? just for grins, '-7' --> -7 works just fine, so what is it with '+'?
hi all,
i'm trying to convert a string to an integer. the string is '+7' (43, 55). so i thought Integer fromString: aString would be the answer. not so easy. it fails with an 'Invalid format for Integer' . not sure why it's an invalid format, but be that as
presence of the positive sign is seen as an error.thanks in advance for help,
johnInteger class>>#readFrom: only ever checks for the existence of negative sign to signify a negative number, not the positive sign to signify a positive number. I guess a number without a positive sign is always considered a positive number and the
You will have to strip the positive sign (aString reject: [ :each | each = $+ ])thanks vince,
Vince
On Monday, October 25, 2021 at 7:59:05 PM UTC-4, vin...@gmail.com wrote:as it may, what are my options? just for grins, '-7' --> -7 works just fine, so what is it with '+'?
On Tuesday, 26 October 2021 at 06:00:51 UTC+10, john c wrote:
hi all,
i'm trying to convert a string to an integer. the string is '+7' (43, 55). so i thought Integer fromString: aString would be the answer. not so easy. it fails with an 'Invalid format for Integer' . not sure why it's an invalid format, but be that
presence of the positive sign is seen as an error.thanks in advance for help,
johnInteger class>>#readFrom: only ever checks for the existence of negative sign to signify a negative number, not the positive sign to signify a positive number. I guess a number without a positive sign is always considered a positive number and the
You will have to strip the positive sign (aString reject: [ :each | each = $+ ])
Vincethanks vince,
i arrived at that same conclusion and i'm modifying as we speak. with that said, it strikes me that a valid format should be accepted rather than putting on every developer.
sorry, just ranting.
john
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 293 |
Nodes: | 16 (2 / 14) |
Uptime: | 210:50:53 |
Calls: | 6,619 |
Calls today: | 1 |
Files: | 12,168 |
Messages: | 5,317,250 |