{"id":12162,"date":"2025-04-18T10:11:19","date_gmt":"2025-04-18T10:11:19","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=12162"},"modified":"2025-04-18T10:11:19","modified_gmt":"2025-04-18T10:11:19","slug":"parse-a-string-to-a-number-in-dart","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/flutter\/parse-a-string-to-a-number-in-dart","title":{"rendered":"How to Parse a String into a Number with Dart?"},"content":{"rendered":"<p><strong>&#8211; Flutter provide int.parse() and int.tryParse() method.<\/strong><\/p>\n<h3>1. int.parse()<\/h3>\n<p>&#8211; We use this method when we are sure like string contains only numbers. If string contain alphabet then it throws a Format Exception.<\/p>\n<h3>. int.tryParse()<\/h3>\n<p>&#8211;  We use this method when we are not sure like string may not contain only numbers.We can set default value if string may contain alphabet.<\/p>\n<h3>Example:-<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/04\/18100937\/unnamed-4.png\" alt=\"Output\" width=\"380\" height=\"183\" class=\"alignright size-full wp-image-12164\" srcset=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/04\/18100937\/unnamed-4.png 380w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/04\/18100937\/unnamed-4-300x144.png 300w\" sizes=\"(max-width: 380px) 100vw, 380px\" \/><\/p>\n<h3>Output<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/04\/18101054\/unnamed-1-1.png\" alt=\"output2\" width=\"78\" height=\"58\" class=\"alignright size-full wp-image-12165\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8211; Flutter provide int.parse() and int.tryParse() method. 1. int.parse() &#8211; We use this method when we are sure like string contains only numbers. If string contain alphabet then it throws a Format Exception. . int.tryParse() &#8211; We use this method when we are not sure like string may not contain only numbers.We can set default [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":12163,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[15],"tags":[],"class_list":["post-12162","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-flutter"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/12162"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=12162"}],"version-history":[{"count":1,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/12162\/revisions"}],"predecessor-version":[{"id":12166,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/12162\/revisions\/12166"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/12163"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=12162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=12162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=12162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}