{"id":1575,"date":"2012-05-29T09:01:14","date_gmt":"2012-05-29T16:01:14","guid":{"rendered":"http:\/\/juixe.com\/techknow\/?p=1575"},"modified":"2012-05-28T12:16:20","modified_gmt":"2012-05-28T19:16:20","slug":"formatting-numeric-value-to-string-in-java","status":"publish","type":"post","link":"http:\/\/juixe.com\/techknow\/index.php\/2012\/05\/29\/formatting-numeric-value-to-string-in-java\/","title":{"rendered":"Formatting an Integer to String in Java"},"content":{"rendered":"<p>There are times when you need to format a integer or double value into a String, with the comma for values larger than a thousand.  If you need to format a numeric value correctly based on the local formatting rules for numbers use the <strong>NumberFormat<\/strong> class.  Different locales have different formatting rules, for example in France they use the comma as a decimal point where in the United States the comma is used for delimiting large numbers.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ndouble val = 123456.78;\r\nSystem.out.println(val); \/\/ 123456.78\r\n\r\n\/\/ Use default locale to format string\r\nString localFormat = NumberFormat.getNumberInstance().format(val);\r\nSystem.out.println(localFormat); \/\/ 123,456.78\r\n\t\t\r\nString frenchFormat = NumberFormat.getNumberInstance(Locale.FRANCE).format(val);\r\nSystem.out.println(frenchFormat); \/\/ 123\u00c2\u00a0456,78\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>There are times when you need to format a integer or double value into a String, with the comma for values larger than a thousand. If you need to format a numeric value correctly based on the local formatting rules for numbers use the NumberFormat class. Different locales have different formatting rules, for example in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[15,19],"tags":[698,802,696,697],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p902K-pp","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/1575"}],"collection":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/comments?post=1575"}],"version-history":[{"count":1,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/1575\/revisions"}],"predecessor-version":[{"id":1576,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/1575\/revisions\/1576"}],"wp:attachment":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/media?parent=1575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/categories?post=1575"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/tags?post=1575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}