From 8031f6c345d2280df7ddb13adb13a846e65178b4 Mon Sep 17 00:00:00 2001 From: Uwe Kubosch Date: Thu, 29 Feb 2024 11:04:19 +0100 Subject: [PATCH] Patch BigDecimal#to_s/Float#to_s to return localized formatted string --- build.gradle | 2 +- src/main/resources/ruby/bigdecimal_ext.rb | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index dc68311..6845d51 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group 'no.datek' -version '0.13.4' +version '0.13.5' final String JRUBY_VERSION = '9.4.5.0'; repositories { diff --git a/src/main/resources/ruby/bigdecimal_ext.rb b/src/main/resources/ruby/bigdecimal_ext.rb index 5ec0c3f..2fbb67c 100644 --- a/src/main/resources/ruby/bigdecimal_ext.rb +++ b/src/main/resources/ruby/bigdecimal_ext.rb @@ -2,9 +2,20 @@ require 'bigdecimal' -class BigDecimal - alias :to_fs :to_s +module BigDecimalExt + def to_s(format = nil) + if format + return super(format) + end + java.text.NumberFormat.getInstance(Thread.current[:locale]).format(self) + end + + def to_fs(format = nil) + to_s(format || 'F') + end end +BigDecimal.prepend BigDecimalExt +Float.prepend BigDecimalExt class Java::JavaMath::BigDecimal def to_bd