string-format: String.format/formatted/printf cheat sheet module (specifier anatomy, rounding vs C printf, locales, Indian lakh/crore grouping Formatter cannot do, format exceptions, %t dates, concat cost), 11 contract tests
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b7Sr2zcoRD2watXv1G
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
/* The same four values RoundingDemo formats, through C's printf, for comparison with Java's %f. */
|
||||
#include <stdio.h>
|
||||
int main(void) {
|
||||
printf("C printf %%.2f of 2.675 : %.2f\n", 2.675);
|
||||
printf("C printf %%.1f of 0.35 : %.1f\n", 0.35);
|
||||
printf("C printf %%.2f of 1.005 : %.2f\n", 1.005);
|
||||
printf("C printf %%.2f of 0.125 : %.2f\n", 0.125);
|
||||
return 0;
|
||||
}
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regenerates every file in output/. Timing output (07) is indicative and drifts between runs.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
mvn -q -B compile
|
||||
run() { java -Dstdout.encoding=UTF-8 -cp target/classes "com.ankurm.stringformat.$1" 2>&1 | grep -v '^Picked up JAVA_TOOL_OPTIONS' > "output/$2.txt"; }
|
||||
run BasicsDemo 01-basics
|
||||
run ReportTableDemo 02-report-table
|
||||
run RoundingDemo 03-rounding
|
||||
run IndianGroupingDemo 04-indian-grouping
|
||||
run LocaleDemo 05-locale
|
||||
run FormatErrorsDemo 06-format-errors
|
||||
run FormattedAndPrintfDemo 07-formatted-printf
|
||||
run ConcatBenchmarkDemo 08-concat-benchmark
|
||||
if command -v gcc >/dev/null; then
|
||||
gcc scripts/printf_compare.c -o /tmp/printf_compare && /tmp/printf_compare > output/10-c-printf.txt
|
||||
fi
|
||||
run DateTimeDemo 11-datetime
|
||||
mvn -B test 2>&1 | grep -E 'Tests run|BUILD|ERROR|FAIL' | grep -v 'Picked up' > output/09-tests.txt
|
||||
echo "regenerated:"; ls output
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# Run one demo: scripts/run.sh BasicsDemo
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
mvn -q -B compile
|
||||
java -Dstdout.encoding=UTF-8 -cp target/classes "com.ankurm.stringformat.${1:?demo class name}"
|
||||
Reference in New Issue
Block a user