MediaWiki:Gadget-fa-bid-calculator.js: Difference between revisions

Thousands separators in the salary field
Bid to beat must clear the standing bid by 0.2 points
Line 11: Line 11:
var MIN_OFFER = 500000,
var MIN_OFFER = 500000,
MIN_RAISE = 200000,
MIN_RAISE = 200000,
MIN_RAISE_POINTS = 0.2,
MAX_YEARS = 4,
MAX_YEARS = 4,
MAX_YEARS_35 = 2,
MAX_YEARS_35 = 2,
YEAR_POINTS = 1.5;
YEAR_POINTS = 1.5;


function money( n ) {
function money( n ) {
Line 256: Line 258:
box.className = 'tc-calc-note';
box.className = 'tc-calc-note';


if ( total > target ) {
// A bid must clear the standing one by at least MIN_RAISE_POINTS, so
// the bar is target + 0.2, not merely more than target. Everything
// here is counted in tenths of a point: 0.1 points is exactly
// $100,000 and a year is exactly 15 tenths, so integer arithmetic
// gets the answer that 0.2 + 2.0 in binary floating point does not.
var requiredTenths = Math.round( target * 10 ) + ( MIN_RAISE_POINTS * 10 );
 
if ( Math.round( total * 10 ) >= requiredTenths ) {
box.textContent = 'This already beats ' + pts( target ) + ' points.';
box.textContent = 'This already beats ' + pts( target ) + ' points.';
} else {
} else {
// cheapest money-only raise, in $200,000 steps
var salaryTenths = requiredTenths - y * ( YEAR_POINTS * 10 ),
var needed = ( target - total ) * 1000000,
newSalary = Math.max( salaryTenths * 100000, MIN_OFFER );
raises = Math.max( 1, Math.ceil( needed / MIN_RAISE ) ),
newSalary = s + ( raises * MIN_RAISE );
while ( points( y, newSalary ) <= target ) {
newSalary += MIN_RAISE;
}
box.textContent = 'To beat ' + pts( target ) + ' points at ' + y +
box.textContent = 'To beat ' + pts( target ) + ' points at ' + y +
( y === 1 ? ' year' : ' years' ) + ': ' + money( newSalary ) +
( y === 1 ? ' year' : ' years' ) + ': ' + money( newSalary ) +