Skip to content

Commit

Permalink
update ledger example (#354)
Browse files Browse the repository at this point in the history
many many attempts later
problem: formatting string using cultureinfo from .net (either [cultureinfo] or `ToString("C")` method. It won't play nice with ubuntu env and result in fail checks
solve: build the string with other methods
  • Loading branch information
glaxxie authored Feb 17, 2024
1 parent c043e82 commit 58e6f75
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions exercises/practice/ledger/.meta/Ledger.example.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ Class LedgerEntry{
$dateFormat = $this.GetDateFormat($Currency, $Locale)

$dateStr = $this.Date.ToString($dateFormat)
$moneyStr = ($this.Change / 100).ToString("C2", [cultureinfo]::new($Locale))
$moneyStr = "{0:N2}" -f ($this.Change / 100)
$sign = $Currency -eq "USD" ? [char]0x0024 : [char]0x20AC

if ($Currency -eq "EUR" -and $Locale -eq "en-US") {
$moneyStr = $moneyStr -replace '\$', ''
if ($Locale -eq "nl-NL") {
$moneyStr = $moneyStr.Replace(',', '*').Replace('.', ',').Replace('*', '.')
$moneyStr = "$sign $moneyStr"
}
if ($Currency -eq "USD" -and $Locale -eq "nl-NL") {
$moneyStr = $moneyStr -replace '', '$'

if ($Locale -eq "en-US") {
$moneyStr = $this.Change -lt 0 ? "($sign$($moneyStr.Substring(1)))" : "$sign$moneyStr"
}

if ($this.Desc.Length -gt 25) {
$this.Desc = $this.Desc.Substring(0,22) + "..."
}
Expand Down Expand Up @@ -127,4 +131,4 @@ Function FormatEntries {
$table += $entry.Format($Currency, $Locale)
}
$table -join "`n"
}
}

0 comments on commit 58e6f75

Please sign in to comment.