Skip to content

Instantly share code, notes, and snippets.

View 1FahadShakeel's full-sized avatar
🏠
Working from home

Fahad Shakeel 1FahadShakeel

🏠
Working from home
View GitHub Profile
function format(input) {
// input.value = (input.value).toLocaleString('en-US');
var nStr = input.value + "";
nStr = nStr.replace(/\,/g, "");
x = nStr.split(".");
x1 = x[0];
x2 = x.length > 1 ? "." + x[1] : "";
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, "$1" + "," + "$2");
@1FahadShakeel
1FahadShakeel / compound_interest_with_regular_intervals.js
Created August 22, 2022 09:00
compound interest with regular intervals
let princ = 10000; // start deposit
let add = 500; // monthly deposit (need plus it every year)
let rate = 0.06; // interest rate divided to create decimal
let months = (41 * 12); //41 years of monthly contributions
for (let i = 1; i <= months; i++) {
princ += princ * (rate / 12);
princ += add;
console.log(princ);
}
@1FahadShakeel
1FahadShakeel / hide_arrow_button_input.css
Created August 22, 2022 06:28
hide arrows from input type number
/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
/* Firefox */
input[type=number] {
-moz-appearance: textfield;
@1FahadShakeel
1FahadShakeel / pmt_function_excel.js
Created August 2, 2022 06:30
The Excel PMT Function in JavaScript
function pmt(rate, nper, pv) {
if (rate == 0) return -(pv) / nper;
var pvif = Math.pow(1 + rate, nper);
var PMT = rate / (pvif - 1) * -(pv * pvif);
return PMT;
}
@1FahadShakeel
1FahadShakeel / rate_function_excel.js
Created August 2, 2022 06:28
The excel RATE() function in Javascript
var RATE = function(nper, pmt, pv, fv, type, guess) {
// Sets default values for missing parameters
fv = typeof fv !== 'undefined' ? fv : 0;
type = typeof type !== 'undefined' ? type : 0;
guess = typeof guess !== 'undefined' ? guess : 0.1;
// Sets the limits for possible guesses to any
// number between 0% and 100%
var lowLimit = 0;
var highLimit = 1;