{"id":3315,"date":"2025-12-24T10:00:44","date_gmt":"2025-12-24T15:00:44","guid":{"rendered":"https:\/\/www.mymiller.name\/wordpress\/?p=3315"},"modified":"2025-12-24T10:00:44","modified_gmt":"2025-12-24T15:00:44","slug":"__trashed-10","status":"publish","type":"post","link":"https:\/\/www.mymiller.name\/wordpress\/java_new_features\/__trashed-10\/","title":{"rendered":"Java Compact Number Formatting"},"content":{"rendered":"\n<p>Java 12 introduced a new feature known as &#8220;Compact Number Formatting&#8221; that makes it easier to format numbers in a compact, readable way. This feature is especially useful when dealing with large numbers, such as those used in finance or scientific calculations.<\/p>\n\n\n\n<p>In this blog article, we will explore what compact number formatting is, how it works, and how to use it in your Java applications.<\/p>\n\n\n\n<p>What is Compact Number Formatting?<\/p>\n\n\n\n<p>Compact Number Formatting is a new feature in Java 12 that allows you to format large numbers in a more compact and readable way. This feature is especially useful when dealing with numbers that are too large to be easily read by humans, such as those used in finance or scientific calculations.<\/p>\n\n\n\n<p>The compact number formatting feature provides a way to format numbers in a way that is both concise and easy to read. It achieves this by using symbols to represent large numbers rather than writing out the entire number in digits. For example, instead of writing &#8220;1,000,000&#8221;, we can use the symbol &#8220;1M&#8221; to represent the same number.<\/p>\n\n\n\n<p>How Compact Number Formatting Works<\/p>\n\n\n\n<p>Compact Number Formatting works by mapping a numeric value to a compact representation using a set of rules. These rules are based on the current locale, which determines the symbols and formatting rules used for different number ranges.<\/p>\n\n\n\n<p>The rules for compact number formatting are defined in the Unicode Common Locale Data Repository (CLDR) and are based on the language and region of the current locale. The CLDR defines a set of symbols for different number ranges, such as &#8220;K&#8221; for thousands, &#8220;M&#8221; for millions, and &#8220;B&#8221; for billions. It also defines the formatting rules for each range, such as the number of significant digits to display and whether to use scientific notation.<\/p>\n\n\n\n<p>To format a number using compact number formatting, we use the <code>NumberFormat.getCompactNumberInstance()<\/code> method to obtain a compact number formatter for the current locale. We can then use this formatter to format a number using the <code>format()<\/code> method.<\/p>\n\n\n\n<p>Example Usage<\/p>\n\n\n\n<p>Let&#8217;s take a look at an example to see how compact number formatting works in practice. Suppose we have a large number, such as 1,234,567,890. We can format this number using compact number formatting as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>NumberFormat nf = NumberFormat.getCompactNumberInstance(Locale.US, NumberFormat.Style.SHORT); \nString formatted = nf.format(1234567890); \nSystem.out.println(formatted); \n<\/code><\/pre>\n\n\n\n<p>In this example, we obtain a compact number formatter for the US locale using the <code>NumberFormat.getCompactNumberInstance()<\/code> method. We then use this formatter to format the number 1,234,567,890 using the <code>format()<\/code> method, which returns the compact representation &#8220;1.2B&#8221;.<\/p>\n\n\n\n<p>The <code>NumberFormat.Style.SHORT<\/code> argument specifies that we want to use the shortest possible representation for the given number. There are also other styles available, such as <code>LONG<\/code> and <code>NARROW<\/code>, which provide different levels of detail and specificity.<\/p>\n\n\n\n<p>Conclusion<\/p>\n\n\n\n<p>Compact Number Formatting is a useful feature introduced in Java 12 that allows us to format large numbers in a more compact and readable way. This feature uses symbols to represent large numbers, which makes them easier to read and understand. By using the <code>NumberFormat.getCompactNumberInstance()<\/code> method, we can obtain a compact number formatter for the current locale and use it to format large numbers in a concise and readable way.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java 12 introduced a new feature known as &#8220;Compact Number Formatting&#8221; that makes it easier to format numbers in a compact, readable way. This feature is especially useful when dealing with large numbers, such as those used in finance or scientific calculations. In this blog article, we will explore what compact number formatting is, how [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3347,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[458],"tags":[],"series":[],"class_list":["post-3315","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java_new_features"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/vintage-g314845ad2_640.jpg?fit=640%2C425&ssl=1","jetpack-related-posts":[{"id":3388,"url":"https:\/\/www.mymiller.name\/wordpress\/java_new_features\/vector-api-for-computations\/","url_meta":{"origin":3315,"position":0},"title":"Vector API for computations","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Java 16 introduced a new feature called the Vector API, which provides a set of low-level vector operations for performing mathematical calculations on large sets of data. The Vector API is designed to take advantage of the hardware capabilities of modern CPUs, such as SIMD (Single Instruction Multiple Data) instructions,\u2026","rel":"","context":"In &quot;Java New Features&quot;","block_context":{"text":"Java New Features","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java_new_features\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/board-g12f4be736_640.jpg?fit=640%2C424&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/board-g12f4be736_640.jpg?fit=640%2C424&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/board-g12f4be736_640.jpg?fit=640%2C424&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3401,"url":"https:\/\/www.mymiller.name\/wordpress\/java\/ansi-colors\/","url_meta":{"origin":3315,"position":1},"title":"ANSI Colors","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Title: Using ANSI Colors in Java Code for String Styling Introduction: ANSI colors provide a powerful way to add visual enhancements and improve the readability of text in a terminal or console environment. In Java, you can leverage ANSI escape codes to apply various colors and formatting to your strings.\u2026","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2019\/04\/coding-924920_640.jpg?fit=640%2C426&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2019\/04\/coding-924920_640.jpg?fit=640%2C426&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2019\/04\/coding-924920_640.jpg?fit=640%2C426&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3451,"url":"https:\/\/www.mymiller.name\/wordpress\/java\/streamlining-java-project-development-with-gradle-a-comprehensive-configuration-guide\/","url_meta":{"origin":3315,"position":2},"title":"Streamlining Java Project Development with Gradle: A Comprehensive Configuration Guide","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Setting up a Gradle project with subprojects involves a thoughtful configuration to ensure a smooth development process. In this article, we'll walk through the step-by-step process of configuring a Gradle project to incorporate essential tools and plugins such as Spotless, Javadoc, Dependency Check, License Info, SonarLint, JaCoCo, and Test Reporting.\u2026","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/04\/spreadsheet-309088_640.png?fit=640%2C626&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/04\/spreadsheet-309088_640.png?fit=640%2C626&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/04\/spreadsheet-309088_640.png?fit=640%2C626&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3362,"url":"https:\/\/www.mymiller.name\/wordpress\/java_new_features\/pattern-matching-for-instanceof\/","url_meta":{"origin":3315,"position":3},"title":"Pattern Matching for instanceof","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Java 16 introduced a new feature called \"Pattern Matching for instanceof\" which simplifies the process of casting objects in Java. This feature improves the readability and safety of code that uses instanceof and casting by allowing developers to combine the two operations into a single step. In this blog article,\u2026","rel":"","context":"In &quot;Java New Features&quot;","block_context":{"text":"Java New Features","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java_new_features\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/jigsaw-gcae0977ae_640.png?fit=640%2C455&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/jigsaw-gcae0977ae_640.png?fit=640%2C455&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/jigsaw-gcae0977ae_640.png?fit=640%2C455&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3111,"url":"https:\/\/www.mymiller.name\/wordpress\/java_tips\/java-tips-part-1\/","url_meta":{"origin":3315,"position":4},"title":"Java Tips Part 1","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Over the years I have done a number of code reviews there have been a number of common mistakes that I have found. So here are my Java tips a series of posts going over these tips. Tip 1: Throw original Exception Many times in our code we will catch\u2026","rel":"","context":"In &quot;Java Tips&quot;","block_context":{"text":"Java Tips","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java_tips\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2021\/12\/sam-dan-truong-rF4kuvgHhU-unsplash-scaled-e1640791434235.jpg?fit=640%2C427&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2021\/12\/sam-dan-truong-rF4kuvgHhU-unsplash-scaled-e1640791434235.jpg?fit=640%2C427&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2021\/12\/sam-dan-truong-rF4kuvgHhU-unsplash-scaled-e1640791434235.jpg?fit=640%2C427&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3353,"url":"https:\/\/www.mymiller.name\/wordpress\/lambda_stream\/java-teeing-collectors\/","url_meta":{"origin":3315,"position":5},"title":"Java Teeing Collectors","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Java 12 introduced a new collector called the Teeing collector. This collector allows you to process elements with two different collectors simultaneously and combine the results into a single output. In this article, we'll take a closer look at the Teeing collector and how you can use it in your\u2026","rel":"","context":"In &quot;Lambda's and Streams&quot;","block_context":{"text":"Lambda's and Streams","link":"https:\/\/www.mymiller.name\/wordpress\/category\/lambda_stream\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/lost-places-g4dcac2ba2_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/lost-places-g4dcac2ba2_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/06\/lost-places-g4dcac2ba2_640.jpg?fit=640%2C427&ssl=1&resize=525%2C300 1.5x"},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/comments?post=3315"}],"version-history":[{"count":3,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3315\/revisions"}],"predecessor-version":[{"id":3348,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3315\/revisions\/3348"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media\/3347"}],"wp:attachment":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media?parent=3315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/categories?post=3315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/tags?post=3315"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/series?post=3315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}