'From Base' operation now supports numbers with fractional parts.
This commit is contained in:
parent
3788a9161a
commit
706423462d
@ -46,7 +46,19 @@ const Base = {
|
|||||||
if (radix < 2 || radix > 36) {
|
if (radix < 2 || radix > 36) {
|
||||||
throw "Error: Radix argument must be between 2 and 36";
|
throw "Error: Radix argument must be between 2 and 36";
|
||||||
}
|
}
|
||||||
return parseInt(input.replace(/\s/g, ""), radix);
|
|
||||||
|
var number = input.replace(/\s/g, "").split("."),
|
||||||
|
result = parseInt(number[0], radix) || 0;
|
||||||
|
|
||||||
|
if (number.length === 1) return result;
|
||||||
|
|
||||||
|
// Fractional part
|
||||||
|
for (var i = 0; i < number[1].length; i++) {
|
||||||
|
var digit = parseInt(number[1][i], radix);
|
||||||
|
result += digit / Math.pow(radix, i+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -13,7 +13,13 @@ const CyberChef = module.exports = {
|
|||||||
|
|
||||||
bake: function(input, recipeConfig) {
|
bake: function(input, recipeConfig) {
|
||||||
this.chef = new Chef();
|
this.chef = new Chef();
|
||||||
return this.chef.bake(input, recipeConfig, {}, 0, false);
|
return this.chef.bake(
|
||||||
|
input,
|
||||||
|
recipeConfig,
|
||||||
|
{},
|
||||||
|
0,
|
||||||
|
false
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user