帮助翻译jquery滑块的值 [英] Help with translating values of a jquery slider
问题描述
我有一个jQuery滑块,用户可以拖动选择0-100(或1-100)的值。
我想使用滑块值用户选择另一个变量值的百分比。
用于计算用户养老金价值和一次性总和价值。这个想法是,滑块值越高,用户养老金的百分比越大被用作养老金牺牲,这反过来增加了他们的一次性总和价值。
例如:
fsb = 400000
pension_2008 = fsb / 80 - (pensionSacrifice);
滑块值= 0到100(由用户设置)
(pensionScarifice的最大值可以是pension_2008值的四分之一)
然后我的公式设置为:
I have a jQuery slider which the user can drag selecting values from 0-100 (or 1-100).
I want to use the slider value the user selects as a percentage of another variable value.
Its to work out a users pension value and a lump sum value. The idea is that the higher the slider value the greater percentage of the users pension is used as a pension sacrifice which in turn increases their lump sum value.
for example:
fsb = 400000
pension_2008 = fsb/80 - (pensionSacrifice);
slider value = 0 to 100 (set by user)
(maximum value the pensionScarifice can be is a quarter of the pension_2008 value)
then my formula is set as:
pensionSacrifice = parseInt(pension_2008) /4 *(lumpSumSlide)/100;
答案(如果用户幻灯片100)应= 1250
例如
pensionSacrifice 5000/4 = 1250
* 100/100 = 1250
然而,我的pensionSacrifice文本框返回值1001.25和pension_2008 = 4005.05
有时候我得到的结果不一致前后移动滑块。
pensionSacrifice应该在0 t之间变化o 1250(但是从0到1001)
pension_2008应该在3750到5000之间变化(但从4000到5000左右)
有人知道我的配方有什么问题吗?
也许我应该将滑块的最小值和最大值设置为变量值而不是0-100并以百分比形式计算出来?
如果需要我可以提交完整的代码,但只是想保持简单。
我尝试过的方法:
the answer (if user slides to 100) should = 1250
e.g.
pensionSacrifice 5000/4 = 1250
*100 /100 = 1250
however, my pensionSacrifice textbox returns a value of 1001.25 and pension_2008 = 4005.05
and sometimes I get inconsistent results slightly when I move the slider back and forth.
pensionSacrifice should vary from 0 to 1250 (but goes from 0 to 1001)
pension_2008 should vary from 3750 to 5000 (but goes from around 4000 to 5000)
anyone know what is wrong with my formula please?
maybe I should set the min and max value of slider to a variable value rather 0-100 and working it out as a percentage?
I can submit full code if required, but just trying to keep it simple.
What I have tried:
function doMath() {
//variable = value (declare all variables)
var lumpSumSlide = $("#slidervalue").val();
var stdlumpSum = $("#stdlumpSum").val();
var pension_2008 = $("#pension_2008").val();
var annualSalary = $("#annualSalary").val();
var fsb = $("#fsb").val();//final salary benefits
var years = $("#years").val();//years they have paid into scheme
var pensionSacrifice = $("#pensionSacrifice").val();//members chosen pension sacrifice
var maxPensionSacrifice = $("#pensionSacrifice").val();//max pension one can give up
//other values - max lump sum/tax free lumpsum etc
//put maths calcs here
fsb = (annualSalary * years);
pension_2008 = fsb/80 - (pensionSacrifice); //+parseInt(annualSalary);
stdlumpSum = pension_2008 * 3;
maxPensionSacrifice=pension_2008/4;
pensionSacrifice = maxPensionSacrifice * (lumpSumSlide)/100;
//round off calc to 2 dec places
$("#pension_2008").val(custRound(pension_2008,2));
$("#annualSalary").val(custRound(annualSalary,2));
$("#fsb").val(custRound(fsb,2));
$("#stdlumpSum").val(custRound(stdlumpSum,2));
$("#pensionSacrifice").val(custRound(pensionSacrifice,2));
$("#maxPensionSacrifice").val(custRound(maxPensionSacrifice,2));
}
//round off function
function custRound(x,places) {
return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places)
}
推荐答案
(#slidervalue)。val() ;
var stdlumpSum =
("#slidervalue").val(); var stdlumpSum =
(#stdlumpSum)。val();
var pension_2008 =
("#stdlumpSum").val(); var pension_2008 =
(#pension_2008)。val();
var annualSalary =
("#pension_2008").val(); var annualSalary =
这篇关于帮助翻译jquery滑块的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!