I have a full amount including VAT and i want to seperate the net price and the vat value.
The example is final price is 80.60 and the vat is 24%. What is the net price and what is the vat value? The answer should be net price is 65.00 and the vat value = 15.60.
For some reason typescript calculates 65.00 and 15.599999999999994. At the moment i dont want to round, the result should be 15.60 clearly though. I know there are other ansers on how to calculate the Vat , but my question is pretty specific whats wrong with my code and generated this decimal instead of 15.60.
Here is my code: component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-fpa',
templateUrl: './fpa.component.html',
styleUrls: ['./fpa.component.css']
})
export class FpaComponent implements OnInit {
public netPrice:number;
public fpaPercent:number=24;
public fpaValue:number=0;
public totalPrice:number;
public calc(calcType:string = ''){
this.netPrice = this.totalPrice / ((this.fpaPercent/100)+1);
this.fpaValue = this.totalPrice - this.netPrice;
}
}
component.html
<mat-form-field>
<input [(ngModel)]="netPrice" (keyup)="calc('byNetPrice');" matInput placeholder="Net Price">
</mat-form-field>
<mat-form-field>
<input [(ngModel)]="fpaPercent" (keyup)="calc();" matInput placeholder="% Vat">
</mat-form-field>
<mat-form-field>
<input [(ngModel)]="fpaValue" (keyup)="calc('byFpaValue');" matInput placeholder="Vat Value">
</mat-form-field>
<mat-form-field>
<input [(ngModel)]="totalPrice" (keyup)="calc('byFinalPrice');" matInput placeholder="Final Price" >
</mat-form-field>