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

Correção formatFloatCurrency #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions src/FoxAlert.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ function registerFACurrencyEvents() {

function foxCurrencyFloat(prInputID) {
let value = $('#'+prInputID).val();
if(value <= 0){
return getFoxAsomeNumbers("0");
}
if (value.indexOf(",") >= 0) {
let partRight = value.substring(value.indexOf(",")+1,value.length);
let partLeft = value.substring(0,value.indexOf(","));
Expand All @@ -63,28 +66,31 @@ function formatFloatCurrency(input){
//Format float values to string with mask R$ Real Brasil
//inputString Example: "1000.52"
// get input value
if(typeof input !== 'number'){
return 'R$ 0,00';
let input_val
if(isNaN(input)){
input_val = "0";
} else {
let input_val = input.toString();
input_val = parseFloat(input_val).toFixed(2);
input_val = input_val.toString();
input_val = input_val.replace('.',',');
input_val = input.toString();
}
console.log(input_val);

// check for decimal
if (input_val.indexOf(",") >= 0) {
if (input_val.indexOf(",") === (input_val.length -1)) {
return;
}
let partRight = input_val.substring(input_val.indexOf(",")+1,input_val.length);
let partLeft = input_val.substring(0,input_val.indexOf(","));
//alert(partRight);
//alert(partLeft);
return 'R$ ' + formatNumber(partLeft) + ',' + partRight;
//alert(number);
} else {
return 'R$ ' + formatNumber(input_val) + ',00'
input_val = parseFloat(input_val).toFixed(2);
input_val = input_val.toString();
input_val = input_val.replace('.',',');

// check for decimal
if (input_val.indexOf(",") >= 0) {
if (input_val.indexOf(",") === (input_val.length -1)) {
return;
}
let partRight = input_val.substring(input_val.indexOf(",")+1,input_val.length);
let partLeft = input_val.substring(0,input_val.indexOf(","));
//alert(partRight);
//alert(partLeft);
return 'R$ ' + formatNumber(partLeft) + ',' + partRight;
//alert(number);
} else {
return 'R$ ' + formatNumber(input_val) + ',00'
}
}
function formatCurrency(input, prAux) {
Expand Down