l am trying to subtract two numbers which already exists. when I click on cut
method, its returning NaN
export class Tab2Page implements OnInit {
categories: AngularFireList<any>;
userBlnc :any // user balance in database
constructor(public af: AngularFireDatabase, public afAuth: AngularFireAuth, public router: Router,
public a: LoadingController, public m: AlertController) { }
ngOnInit(): void {
this.afAuth.authState.subscribe(async user => {
if (user) {
// Getting user balance from database
this.af.list("/users/" + user.uid + '/profile').valueChanges().subscribe((data: any) => {
this.userBlnc = data; // output array
})
} else {
this.router.navigate(['signin'])
}
})
}
// alert dialog to confirm Subtraction
async open(a) {
const alert = await this.m.create({
cssClass: 'my-custom-class',
message: "شراء فئة" + a.name + " بسعر " + a.price + " د٫ع ",
buttons: [
{
text: 'الغاء',
role: 'cancel',
handler: () => {
console.log('Confirm Cancel');
}
}, {
text: 'شراء',
cssClass: 'btn_buy',
handler: () => {
this.cut(a);
}
}
]
});
await alert.present();
}
// excite Subtraction
async cut(a) {
let fpaValue: any
if (Number(this.userBlnc[0])) {
if ( Number(a.price)>Number(this.userBlnc[0])) {
fpaValue = (Number(a.price) - Number(this.userBlnc[0]))
console.log(fpaValue)
alert(fpaValue)
} else {
alert('no balance engough')
}
}
}
}
I found the issue. I realized the numbers in my database were written in " Arabic font " So thats why he return NaN result . So l changed to English numbers and he is working fine . :)