How to format numbers as currency strings

Intl.NumberFormat JavaScript has a number formatter (part of the Internationalization API). Use undefined in place of the first argument (‘en-US’ in the example) to use the system locale (the user locale in case the code is running in a browser). Further explanation of the locale code. Here’s a list of the currency codes. Intl.NumberFormat vs Number.prototype.toLocaleString A final note comparing … Read more

std::string formatting like sprintf

Modern C++ makes this super simple. C++20 C++20 introduces std::format, which allows you to do exactly that. It uses replacement fields similar to those in python: Code from cppreference.com, CC BY-SA and GFDL Check out the compiler support page to see if it’s available in your standard library implementation. As of 2021-11-28, full support is only available in Visual Studio 2019 16.10, which … Read more

Change date format in a Java string

Use LocalDateTime#parse() (or ZonedDateTime#parse() if the string happens to contain a time zone part) to parse a String in a certain pattern into a LocalDateTime. Use LocalDateTime#format() (or ZonedDateTime#format()) to format a LocalDateTime into a String in a certain pattern. Or, when you’re not on Java 8 yet, use SimpleDateFormat#parse() to parse a String in a certain pattern into a Date. Use SimpleDateFormat#format() to format a Date into a String in a certain pattern. See also: Java string to date … Read more