所以我所有的小数都四舍五入到两位。但是,当我单击“键盘或鼠标”图像时,小数位大约是十位数长(例如:36.900000000000006)。我该如何阻止这个。我尝试过使用“.toFixed() 和 .toPrecision()。
这是该页面的链接...比创建小提琴要容易得多。
http://www.ootpik.info/lauren/ootpik5/gethardware.html
我添加了一个小提琴:http: //jsfiddle.net/lolsen7/8uwGH/3/
脚本
$(document).ready(function() {
$(".part,.extra").mouseover(function() {
if(this.className !== 'part selected') {
$(this).attr('src', 'images/placeholder/get_hardware/' + this.id + '.png');
}
$(this).mouseout(function(){
if(this.className !== 'part selected') {
$(this).attr('src', 'images/placeholder/get_hardware/' + this.id + '_grey.png');
}
});
});
var list = document.getElementById("list");
var summaryTotal = document.getElementById("summaryTotal");
var touchtotal = 13.89;
var minitotal = 19.47;
var constant = touchtotal + minitotal;
$('#finaltotal').text(constant);
//station one
var keyboard2 = 59;
var mouse2 = 59;
var printer = 345;
var scale2 = 530;
var display = 175;
var single = 132;
var multi = 260;
var scannerTotal = 0;
var cash = 100;
var storage = 125;
var registerTotal = 0;
//extras
var ipad = 349;
var ipadTotal = 0;
var mobilePrinter = 570;
var mobileTotal = 0;
var printer2 = 345;
var printer2Total = 0;
$(".part").click(function(){
var name = this.id;
var liname = this.alt;
var total = parseFloat((eval(name) * 1.2) /40);
if(this.className != 'part selected')
{
$(this).attr('src','images/placeholder/get_hardware/' + name + '.png');
if(name !== 'multiBar' && name !== 'singleBar' && name !== 'storageDrawer' && name !== 'cashDrawer' )
{
//generate list items
var li = document.createElement("li");
li.setAttribute("id",name + "_li");
li.appendChild(document.createTextNode(liname));
list.appendChild(li);
//touchscreen and mac mini pricing
constant = constant + total;
$('#finaltotal').text(constant);
}
//Scanners if clicked on
else if(name == "multiBar" || name == "singleBar"){
$(".tooltip").show();
$("input").change(function(e){
if($(this).attr("checked", "true")) {
if(this.value == "one") {
// hide and show images based on radio selection
$('#singleBar').attr('src','images/placeholder/get_hardware/singleBar.png');
$('#singleBar').show();
$('#singleBar').toggleClass('selected');
$('#multiBar').hide();
//list item
if($('#single_li').length > 0)
{
$('#single_li').remove();
}
if($('#multi_li').length > 0)
{
$('#multi_li').remove();
}
li = document.createElement("li");
li.setAttribute("id","single_li");
li.appendChild(document.createTextNode("Single-line Barcode Scanner"));
list.appendChild(li);
//pricing
if(scannerTotal !== 0)
{
constant = constant - scannerTotal;
}
scannerTotal = (single * 1.2) /40;
constant = constant + scannerTotal;
$('#finaltotal').text(constant);
}else if(this.value == "two") {
//hide and show images based on radio selection
$('#multiBar').attr('src','images/placeholder/get_hardware/multiBar.png');
$('#multiBar').show();
$('#singleBar').hide();
//list item
if($('#multi_li').length > 0){
$('#multi_li').remove();
}
if($('#single_li').length > 0){
$('#single_li').remove();
}
li = document.createElement("li");
li.setAttribute("id","multi_li");
li.appendChild(document.createTextNode("Multi-line Barcode Scanner"));
list.appendChild(li);
if(scannerTotal !== 0){
constant = constant - scannerTotal;
}
scannerTotal = (multi * 1.2) /40;
constant = constant + scannerTotal;
$('#finaltotal').text(constant);
}
}
});
}
//if register is clicke on
else if(name =="storageDrawer" || name == "cashDrawer"){
$('.tooltip2').show();
$('input').change(function(){
if($(this).attr("checked","true")) {
if(this.value == "three") {
//hide and show images based on radio button selection
$('#cashDrawer').attr('src','images/placeholder/get_hardware/cashDrawer.png');
$('#cashDrawer').show();
$("#storageDrawer").hide();
//list items
if($('#cash_li').length > 0){
$('#cash_li').remove();
}
if($('#storage_li').length > 0){
$('#storage_li').remove();
}
li = document.createElement("li");
li.setAttribute('id','cash_li');
li.appendChild(document.createTextNode("Cash Drawer"));
list.appendChild(li);
//pricing
if(registerTotal !== 0){
constant = constant - registerTotal;
}
registerTotal = (cash * 1.2)/40;
constant = constant + registerTotal;
$('#finaltotal').text(constant);
}else if(this.value == "four") {
$('#storageDrawer').attr('src','images/placeholder/get_hardware/storageDrawer.png');
$('#storageDrawer').show();
$('#cashDrawer').hide();
//list items
if($('#storage_li').length > 0){
$('#storage_li').remove();
}
if($('#cash_li').length > 0){
$('#cash_li').remove();
}
li = document.createElement('li');
li.setAttribute('id','storage_li');
li.appendChild(document.createTextNode("Premium Cash Drawer"));
list.appendChild(li);
//pricing
if(registerTotal !== 0){
constant = constant - registerTotal;
}
registerTotal = (storage * 1.2)/40;
constant = constant + registerTotal;
$('#finaltotal').text(constant);
}
}
});
}
$(this).toggleClass('selected');
}
else if (this.className == 'part selected')
{
$(this).attr('src','images/placeholder/get_hardware/' + name + '_grey.png');
if(name !== 'multiBar' && name !== 'singleBar' && name !== 'storageDrawer' && name !== 'cashDrawer')
{
constant = constant - total;
$('#finaltotal').text(constant);
$("#" + name + "_li").remove();
}
//Scanners
else if(name == 'multiBar' || name == 'singleBar')
{
//Hides Tooltip when de-selecting item
$(".tooltip").hide();
// removes pricing
console.log(scannerTotal);
constant = constant - scannerTotal;
scannerTotal = 0;
$('#finaltotal').text(constant);
//Removes any List items
if($('#multi_li').length > 0)
{
$('#multi_li').remove();
}
if($('#single_li').length > 0)
{
$('#single_li').remove();
}
//Sets Inputs to deselected
$("input[name='group1']").attr("checked",false);
}
//cash drawers || registers
else if(name == 'storageDrawer' || name == 'cashDrawer')
{
$('.tooltip2').hide();
//removes pricing
console.log(registerTotal);
constant = constant - registerTotal;
registerTotal = 0;
$('#finaltotal').text(constant);
//remove any list items
if($('#storage_li').length > 0)
{
$('#storage_li').remove();
}
if($('#cash_li').length > 0)
{
$('#cash_li').remove();
}
//Sets Inputs to deselected
$("input[name='group2']").attr("checked",false);
}
$(this).toggleClass('selected');
}
});
$(".numbers-row").append('<div class="inc buttons">+</div><div class="dec buttons">-</div>');
$(".buttons").on("click", function() {
var $buttons = $(this);
var oldValue = $buttons.parent().find("input").val();
if ($buttons.text() == "+") {
var newVal = parseFloat(oldValue) + 1;
if(newVal > 2 ){
return;
}
} else {
// Don't allow decrementing below zero
if (oldValue > 0) {
var newVal = parseFloat(oldValue) - 1;
} else {
newVal = 0;
}
}
$buttons.parent().find("input").val(newVal);
if($buttons.parent().attr('class') == 'numbers-row ipad'){
if($('#ipad_mini_extra').length > 0){
$('#list').children('#ipad_mini_extra').remove();
//remove pricing
if(newVal == 0){
constant = constant - ipadTotal;
console.log(ipadTotal);
$('#finaltotal').text(constant);
}
}
if(newVal !== 0){
$('#ipad').attr('src',"images/placeholder/get_hardware/ipad.png");
$('#list').append('<li id="ipad_mini_extra">' + newVal + ' iPad mini(s) </li>');
//add pricing
if(ipadTotal !== 0){
constant = constant - ipadTotal;
}
if(newVal == 1){
ipadTotal = (ipad * 1.2) /40;
console.log(ipadTotal);
constant = constant + ipadTotal;
$('#finaltotal').text(constant);
}
if(newVal == 2){
ipadTotal = ((ipad * 2) * 1.2)/40;
console.log(ipadTotal)
constant =constant + ipadTotal;
$('#finaltotal').text(constant);
}
}
else{
$('#ipad').attr('src',"images/placeholder/get_hardware/ipad_grey.png");
}
}
if($buttons.parent().attr('class') == 'numbers-row mobile')
{
if($('#mobile_extra').length > 0)
{
$('#list').children('#mobile_extra').remove();
//remove pricing
if(newVal == 0){
constant = constant - mobileTotal;
console.log(mobileTotal);
$('#finaltotal').text(constant);
}
}
if(newVal !== 0)
{
$('#mobilePrinter').attr('src',"images/placeholder/get_hardware/mobilePrinter.png");
$('#list').append('<li id="mobile_extra">' + newVal + ' Mobile Printer(s) </li>');
//add pricing
if(mobileTotal !== 0){
constant = constant - mobileTotal;
}
if(newVal == 1){
mobileTotal = (mobilePrinter * 1.2) /40;
console.log(mobileTotal);
constant = constant + mobileTotal;
$('#finaltotal').text(constant);
}
if(newVal == 2){
mobileTotal = ((mobilePrinter * 2) * 1.2)/40;
console.log(mobileTotal)
constant =constant + mobileTotal;
$('#finaltotal').text(constant);
}
}
else
{
$('#mobilePrinter').attr('src',"images/placeholder/get_hardware/mobilePrinter_grey.png");
}
}
if($buttons.parent().attr('class') == 'numbers-row printer2')
{
if($('#printer2_extra').length > 0)
{
$('#list').children('#printer2_extra').remove();
//remove pricing
if(newVal == 0){
constant = constant - printer2Total;
console.log(printer2Total);
$('#finaltotal').text(constant);
}
}
if(newVal !== 0)
{
$('#printer2').attr('src',"images/placeholder/get_hardware/printer2.png");
$('#list').append('<li id="printer2_extra"> ' + newVal + ' Kitchen/Bar/Expo Printer(s) </li>');
//add pricing
if(printer2Total !== 0){
constant = constant - printer2Total;
}
if(newVal == 1){
printer2Total = (printer2 * 1.2) /40;
console.log(printer2Total);
constant = constant + printer2Total;
$('#finaltotal').text(constant);
}
if(newVal == 2){
printer2Total = ((printer2 * 2) * 1.2)/40;
console.log(printer2Total)
constant =constant + printer2Total;
$('#finaltotal').text(constant);
}
}
else
{
$('#printer2').attr('src',"images/placeholder/get_hardware/printer2_grey.png");
}
}
});
});