Created
May 16, 2022 15:43
-
-
Save serpicokhan/19601521f2acadabb18be6d129940107 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //extension to convert a string to a number | |
| extension NumberParsing on String { | |
| int customParseInt() { | |
| return int.parse(this); | |
| } | |
| double customParseDouble() { | |
| return double.parse(this); | |
| } | |
| } | |
| void main() { | |
| //various ways to use the extension | |
| var d = '21'.customParseDouble(); | |
| print(d); | |
| var i = NumberParsing('20').customParseInt(); | |
| print(i); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment