Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(pipe): currency pipe missing whitespace on negative amount #46038

Closed
DwieDima opened this issue May 18, 2022 · 7 comments
Closed

bug(pipe): currency pipe missing whitespace on negative amount #46038

DwieDima opened this issue May 18, 2022 · 7 comments
Labels
area: i18n bug P4 A relatively minor issue that is not relevant to core functions
Milestone

Comments

@DwieDima
Copy link

DwieDima commented May 18, 2022

Which @angular/* package(s) are the source of the bug?

common

Is this a regression?

No

Description

When you use currencies, where the symbol is on the left side, there is no whitespace between the symbol and amount, when amount is negative.

Example negative:
image

Example positive:
image

Expected when negative:
image

Please provide a link to a minimal reproduction of the bug

app.module.ts:

import { CurrencyPipe, registerLocaleData } from '@angular/common';
import localeCh from '@angular/common/locales/de-CH';
import localeChExtra from '@angular/common/locales/extra/de-CH';
import { DEFAULT_CURRENCY_CODE, LOCALE_ID, NgModule } from '@angular/core';

registerLocaleData(localeCh, localeChExtra);

@NgModule({
  ...
  providers: [
    { provide: DEFAULT_CURRENCY_CODE, useValue: 'CHF' },
    {
      provide: LOCALE_ID,
      useValue: 'de-CH',
    },
    CurrencyPipe
  ]
})

app.component.html

<!-- CHF-300.00 -->
<div>{{ -300 | currency }}</div

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 13.2.3
Node: 16.14.2
Package Manager: npm 8.5.0
OS: darwin arm64

Angular: 13.2.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router, service-worker

Anything else?

My current workaround is to override the currencyPipe:

import { CurrencyPipe } from '@angular/common';
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'currency',
})
export class CurrencyOverridePipe implements PipeTransform {
  public constructor(private currencyPipe: CurrencyPipe) {}

  public transform(
    value: string | number,
    currencyCode?: string,
    display?: string | boolean,
    digitsInfo?: string,
    locale?: string,
  ): string {
    const result = this.currencyPipe.transform(
      value,
      currencyCode,
      display,
      digitsInfo,
      locale,
    );
    // if the value is negative add whitespace between currency and amount
    if (+value < 0) {
      return result.replace(/-(?=[^-]*$)/, ' -');
    }
    return result;
  }
}
@DwieDima DwieDima changed the title bug(pipe): currency pipe missing whitespace on negative currency bug(pipe): currency pipe missing whitespace on negative amount May 18, 2022
@ngbot ngbot bot added this to the needsTriage milestone May 18, 2022
@jessicajaniuk
Copy link
Contributor

@DwieDima Could you create a reproduction of this within stackblitz? That would be really helpful for us to debug this.

@jessicajaniuk jessicajaniuk added the needs reproduction This issue needs a reproduction in order for the team to investigate further label May 19, 2022
@ngbot ngbot bot modified the milestones: needsTriage, Backlog May 19, 2022
@jessicajaniuk jessicajaniuk added P4 A relatively minor issue that is not relevant to core functions bug labels May 19, 2022
@DwieDima
Copy link
Author

@JoostK
Copy link
Member

JoostK commented May 26, 2022

Relates to #33803.

@jessicajaniuk jessicajaniuk removed the needs reproduction This issue needs a reproduction in order for the team to investigate further label Jul 7, 2022
@JeanMeche
Copy link
Member

JeanMeche commented Dec 2, 2022

For what it's worth, (-1000).toLocaleString('de-CH', {style: 'currency', currency: 'CHF', currencyDisplay:'symbol'}) returns 'CHF-1’000.00' on Chrome, Firefox and Safari.

@JeanMeche
Copy link
Member

JeanMeche commented Jan 30, 2023

The latest CLDR (42) has following for de-CH currencies :

"currencySpacing": {
  "beforeCurrency": {
    "currencyMatch": "[[:^S:]&[:^Z:]]",
    "surroundingMatch": "[:digit:]",
    "insertBetween": " "
  },
  "afterCurrency": {
    "currencyMatch": "[[:^S:]&[:^Z:]]",
    "surroundingMatch": "[:digit:]",
    "insertBetween": " "
  }
},
"standard": "¤ #,##0.00;¤-#,##0.00",

So using de standard de-CH currency format : ¤ #,##0.00 & ¤-#,##0.00.

CHF falls in the afterCurrency case. We see that surroundingMatch checks for a digit after, but - ain't a digit.
So I'd say CHF-310.00 is expected !

@JeanMeche
Copy link
Member

I'll close this as this is related to the CLDR. And if it is a real bug, it should reported there.

@JeanMeche JeanMeche closed this as not planned Won't fix, can't repro, duplicate, stale Sep 16, 2023
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: i18n bug P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

No branches or pull requests

4 participants