Skip to content

Commit

Permalink
Patch BigDecimal#to_s/Float#to_s to return localized formatted string
Browse files Browse the repository at this point in the history
  • Loading branch information
UweKubosch committed Feb 29, 2024
1 parent faed61e commit 8031f6c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 13 additions & 2 deletions src/main/resources/ruby/bigdecimal_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8031f6c

Please sign in to comment.