Discount Calculator
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: ‘Segoe UI’, Tahoma, Geneva, Verdana, sans-serif;
background-color: #f4f6f8;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 1rem;
}
.calc-card {
background: #ffffff;
border: 1px solid #e2e8f0;
border-radius: 16px;
padding: 2rem;
width: 100%;
max-width: 420px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
}
.calc-title {
font-size: 20px;
font-weight: 600;
color: #1a202c;
margin-bottom: 4px;
}
.calc-sub {
font-size: 13px;
color: #718096;
margin-bottom: 1.75rem;
}
.field {
margin-bottom: 1.1rem;
}
.field label {
display: block;
font-size: 13px;
color: #4a5568;
margin-bottom: 6px;
font-weight: 500;
}
.input-wrap {
position: relative;
}
.input-wrap input {
width: 100%;
padding: 11px 40px 11px 14px;
font-size: 16px;
border: 1px solid #cbd5e0;
border-radius: 10px;
background: #f7fafc;
color: #1a202c;
outline: none;
transition: border 0.15s, box-shadow 0.15s;
}
.input-wrap input:focus {
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
background: #fff;
}
.input-wrap input::placeholder {
color: #a0aec0;
}
.input-wrap .unit {
position: absolute;
right: 12px;
top: 50%;
transform: translateY(-50%);
font-size: 14px;
color: #a0aec0;
pointer-events: none;
font-weight: 500;
}
.btn {
width: 100%;
padding: 13px;
font-size: 15px;
font-weight: 600;
background: #1a202c;
color: #ffffff;
border: none;
border-radius: 10px;
cursor: pointer;
margin-top: 1.1rem;
transition: background 0.15s, transform 0.1s;
letter-spacing: 0.2px;
}
.btn:hover {
background: #2d3748;
}
.btn:active {
transform: scale(0.98);
}
.error {
font-size: 12px;
color: #e53e3e;
margin-top: 8px;
display: none;
padding: 8px 12px;
background: #fff5f5;
border-radius: 8px;
border: 1px solid #fed7d7;
}
.result-box {
margin-top: 1.5rem;
background: #f7fafc;
border-radius: 12px;
padding: 1.25rem;
display: none;
border: 1px solid #e2e8f0;
}
.result-box.show {
display: block;
}
.result-row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 6px 0;
}
.result-label {
font-size: 13px;
color: #718096;
}
.result-val {
font-size: 15px;
font-weight: 500;
color: #1a202c;
}
.result-val.discount {
color: #e53e3e;
}
.divider {
border: none;
border-top: 1px solid #e2e8f0;
margin: 10px 0;
}
.final-row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 4px 0;
}
.final-label {
font-size: 15px;
color: #2d3748;
font-weight: 600;
}
.final-val {
font-size: 28px;
font-weight: 700;
color: #1D9E75;
}
.saved-badge {
display: inline-block;
background: #E1F5EE;
color: #0F6E56;
font-size: 12px;
padding: 4px 12px;
border-radius: 20px;
margin-top: 10px;
font-weight: 500;
}
Discount Calculator
মূল দাম ও ছাড়ের পরিমাণ দিলেই চূড়ান্ত দাম দেখাবে
মূল দাম (Original Price)
৳
ছাড়ের হার (Discount %)
%
সঠিক সংখ্যা দিন। ছাড় ০–১০০% এর মধ্যে হতে হবে।
মূল দাম
—
ছাড়
—
চূড়ান্ত দাম
—
আপনি সাশ্রয় করলেন ৳0
function fmt(n) {
return ‘৳’ + n.toLocaleString(‘en-IN’, {
minimumFractionDigits: 0,
maximumFractionDigits: 2
});
}
function calculate() {
const price = parseFloat(document.getElementById(‘price’).value);
const disc = parseFloat(document.getElementById(‘discount’).value);
const err = document.getElementById(‘err’);
const box = document.getElementById(‘result’);
if (isNaN(price) || isNaN(disc) || price < 0 || disc 100) {
err.style.display = ‘block’;
box.classList.remove(‘show’);
return;
}
err.style.display = ‘none’;
const saved = (price * disc) / 100;
const final = price – saved;
document.getElementById(‘r-original’).textContent = fmt(price);
document.getElementById(‘r-saved’).textContent = ‘−’ + fmt(saved);
document.getElementById(‘r-final’).textContent = fmt(final);
document.getElementById(‘r-badge’).textContent = ‘আপনি সাশ্রয় করলেন ‘ + fmt(saved);
box.classList.add(‘show’);
}
document.getElementById(‘price’).addEventListener(‘keydown’, e => {
if (e.key === ‘Enter’) calculate();
});
document.getElementById(‘discount’).addEventListener(‘keydown’, e => {
if (e.key === ‘Enter’) calculate();
});