Since PureBasic has Bin() and Hex() funcitons,
A natural addition would be Val() functions that were number base sensitive using the first character of the string.
If the first character is a "%", treat it as binary
ElseIF the first character is a "$", treat it as hexadecimal
Else treat it as decimal
(I know you can write a function to do this but since the Bin and Hex commands exist, I just think it would be natural for Val to handle them as well)
[Implemented] Number base sensitive Val() functions
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
-
- Enthusiast
- Posts: 169
- Joined: Thu Oct 05, 2006 6:44 am
- Contact:
In my optionion, this feature is not that good.
Imagine, you've got a string with trash or an input made by a user.
%127, $scalar, %11.10, 34h% etc. etc. etc.
The current behaviour of Val, converting a number as far as possible would lead to unexpected results:
Val("321meins") => 321
Val("%127") => 1 (there is no 2 and 7 in binary notation)
I think, it's a good idea, to make Val() and ValQ() accept Bin- and Hex-numbers, but it may lead to problems, using it with the exmaples above.
Maybe, you can also add a function like isNum() natively? If there is a function like isNum(), there should also be no problem with those "trash strings", because now you're able to check strings before the conversion.
These are just my thoughts and suggestions how to handle this request.
Imagine, you've got a string with trash or an input made by a user.
%127, $scalar, %11.10, 34h% etc. etc. etc.
The current behaviour of Val, converting a number as far as possible would lead to unexpected results:
Val("321meins") => 321
Val("%127") => 1 (there is no 2 and 7 in binary notation)
I think, it's a good idea, to make Val() and ValQ() accept Bin- and Hex-numbers, but it may lead to problems, using it with the exmaples above.
Maybe, you can also add a function like isNum() natively? If there is a function like isNum(), there should also be no problem with those "trash strings", because now you're able to check strings before the conversion.
These are just my thoughts and suggestions how to handle this request.
PB 4.30
Code: Select all
onErrorGoto(?Fred)