Hugo vilar
Hugo vilar

Reputation: 101

Formating number as money in angular

someone know how to format a number recived from the API as money? I'm using angular 15.

My HTML look like:

<thead class="fixed-top cabecalhoTabela">
            <mat-card-header>
              <ng-container matColumnDef="TotalInformado">
                <th mat-header-cell *matHeaderCellDef></th>
                <td mat-cell *matCellDef="let guia" class="text-center">
                  <b>Total Informado: R$ {{ guia.TotalInformado }}</b>
                </td>
              </ng-container>

              <ng-container matColumnDef="TotalCalculado">
                <th mat-header-cell *matHeaderCellDef></th>
                <td mat-cell *matCellDef="let guia" class="text-center">
                  <b>Total Calculado: R$ {{ guia.TotalCalculado }}</b>
                </td>
              </ng-container>

              <tr mat-header-row *matHeaderRowDef="colunasCabecalho" id="tr"></tr>
              <tr mat-row *matRowDef="let myRowData; columns: colunasCabecalho" ></tr>
            </mat-card-header>
   </thead>

Upvotes: 0

Views: 72

Answers (1)

Edmunds Folkmanis
Edmunds Folkmanis

Reputation: 572

There is built-in CurrencyPipe

Possibly you want to import locale data. You can do this in app.module

import yourlocale from '@angular/common/locales/yourlocale';
registerLocaleData(yourlocale);

And set default currency and locale providers:

  providers: [
    { provide: DEFAULT_CURRENCY_CODE, useValue: 'YOUR_CURRENCY_CODE' },
    { provide: LOCALE_ID, useValue: 'your_locale' },
  ],

Upvotes: 1

Related Questions