Skip to content

Commit

Permalink
Update fpjust method for use with strings
Browse files Browse the repository at this point in the history
  • Loading branch information
hutou committed Feb 23, 2021
1 parent 9e00e46 commit ac50e17
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: tablo
version: 0.9.4
version: 0.9.5

authors:
- Hubert Toullec <hutou01@gmail.com>

crystal: 0.35.1
crystal: 0.36.1

license: MIT
13 changes: 10 additions & 3 deletions src/commons.cr
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,21 @@ module Tablo
# - nil : mere printf formatting
# - 0 : non signficant zeroes removed and decimal point kept even if no more decimal digits
# - 1 : non signficant zeroes removed and decimal point also removed if no more decimal digits
# - 2 : All blanks if value == zero
# - 2 : like 1, but all blanks if value == zero
# - 3 : same as 0, but zero added after decimal point if no more decimal digits
def fpjust(data : Array(Array(Tablo::CellType?)), col, nbdec, mode)
fvleft = [] of String
fvright = [] of String
data.each do |r|
cell = ("%.#{nbdec}f" % r[col])
dot = cell.index(".").as(Int32)
case r[col]
when Float64
cell = "%.#{nbdec}f" % r[col]
else
cell = r[col].to_s
cell = "0.0" if cell == ""
cell = "#{cell}.0" if cell.index(".").nil?
end
dot = cell.as(String).index(".").as(Int32)
left, right = [cell[0..dot - 1], cell[dot + 1..-1]]
if !mode.nil?
right = right.gsub(/0*$/, "")
Expand Down
2 changes: 1 addition & 1 deletion src/tablo.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ require "./table.cr"
require "./column.cr"

module Tablo
VERSION = "0.9.4"
VERSION = "0.9.5"
extend self
end

0 comments on commit ac50e17

Please sign in to comment.