**I have a code below, i want to change/replace currency format from ($) with (Rp.) in js. I have tired with this, anybody can help me?
function update_total() {
var total = 0;
$('.price').each(function(i){
price = $(this).html().replace("$","");
if (!isNaN(price)) total += Number(price);
});
total = roundNumber(total,2);
$('#subtotal').html("$"+total);
$('#total').html("$"+total);
update_balance();
}
function update_balance() {
var due = $("#total").html().replace("$","") - $("#paid").val().replace("$","");
due = roundNumber(due,2);
$('.due').html("$"+due);
}
function update_price() {
var row = $(this).parents('.item-row');
var price = row.find('.cost').val().replace("$","") * row.find('.qty').val();
price = roundNumber(price,2);
isNaN(price) ? row.find('.price').html("N/A") : row.find('.price').html("$"+price);
update_total();
}
If its only html you want to replace you can use
replace('$','Rp')
Related
i want to show bitcoin price but there are several exchangers. i want to get from bitstamp only but positions of exchangers are changing and can't get only one
i wrote some code on jquery but i can't finish it
$.getJSON('https://chain.so/api/v2/get_price/BTC/USD', function(data) {
var text = ` ${data.data.prices[1].price} `
var integer = parseFloat(text, 10)
var percent = 3
var display = (integer - (integer/100 * percent)).valueOf()
$(".mypanel").html(display.toPrecision(7) + '$');
});
if you want to get request with jquery you should use $.get() and I write you code again (jquery version 3.3.1) get more detail
$(document).ready(function() {
var url= "https://chain.so/api/v2/get_price/BTC/USD";
$.get(url,function(data){
var text = ` ${data.data.prices[1].price} `
var integer = parseFloat(text, 10)
var percent = 3
var display = (integer - (integer/100 * percent)).valueOf()
$(".mypanel").html(display.toPrecision(7) + '$');
console.log(data);
})
});
https://jsfiddle.net/unqL14gs/4/
I'm trying to make a form that contains several different products with different options to calculate and I need to get the total price.
Scenario:
(a+b) * c = price
(a+b) * c = price
(a+b) * c = price
price + price + price = toltal
This is my script, but it doesn't work
$(document).ready(function () {
$("#form").on("keyup", ".form-calc", function () {
var parent = $(this).closest(".items");
var sum = parent.find(".form-line").val((parent.find(".form-cost").val() + parent.find(".form-cost-skift").val()).toFixed(2));
parent.find(".form-line").val((parent.find(".form-qty").val() * sum).toFixed(2));
var total = 0;
$(".form-line").each(function () {
total += parseFloat($(this).val() || 0);
});
$("#total").val(total.toFixed(2));
});
});
JSFiddle
What I'm missing?
Maybe something like this? https://jsfiddle.net/tnzcz8a3/3/
$(document).ready(function () {
$("#form").on("keyup", ".form-calc", function () {
var parent = $(this).closest(".items");
var sum = 0;
var total = 0;
if (!isNaN(parent.find(".form-cost").val())) sum += +parent.find(".form-cost").val();
if (!isNaN(parent.find(".form-cost-skift").val())) sum += +parent.find(".form-cost-skift").val();
if (!isNaN(parent.find(".form-qty").val())) sum *= +parent.find(".form-qty").val();
parent.find(".form-line").val(sum.toFixed(2));
$(".form-line").each(function () {
total += parseFloat($(this).val() || 0);
});
$("#total").val(total.toFixed(2));
});
});
I have prepared this jsfiddle that ilustrates how my script calculate twice the sum of each selected option attribute price. Please help me to solve this issue.
optionsamount is wrong, I mean is calculated twice.. Why is that? Thanks
function update_amounts(){
var sum = 0.0;
var optionsamount = 0.0;
$('#basketorder > tbody > .product').each(function() {
$('.selectedoptionselect option:selected').each(function(){
optprice = $(this).attr('price');
optionsamount+= parseFloat(optprice);
})
var qty = $(this).find('.qty option:selected').val();
var price = $(this).find('.price').val();
var amount = (qty*price);
sum+= (amount + optionsamount);
$(this).find('.amount').text(''+ amount.toFixed(2));
});
$('.total').text(sum);
}
Try this,
function update_amounts(){
var sum = 0.0;
$('#basketorder > tbody > .product').each(function() {
var optionsamount = 0.0;
$(this).find('.selectedoptionselect option:selected').each(function(){
optprice = $(this).attr('price');
optionsamount+= parseFloat(optprice);
})
var qty = $(this).find('.qty option:selected').val();
var price = $(this).find('.price').val();
var amount = (qty*price);
sum+= (amount + optionsamount);
$(this).find('.amount').text(''+ amount.toFixed(2));
});
$('.total').text(sum);
try this
function update_amounts(){
var sum = 0.0;
$('#basketorder > tbody > .product').each(function() {
var optionsamount = 0.0;
$('.selectedoptionselect option:selected').each(function(){
optprice = $(this).attr('price');
optionsamount+= parseFloat(optprice);
})
var qty = $(this).find('.qty option:selected').val();
var price = $(this).find('.price').val();
var amount = (qty*price);
sum+= (amount + optionsamount);
$(this).find('.amount').text(''+ amount.toFixed(2));
});
$('.total').text(sum);
}
I am trying to calculate all fields in the form which have the same class (shown below in the code), I have managed to get this to work, I think I may be setting the wrong value types in javascript as its not adding them together correctly. Its adding them on top of each other and not to each other. so instead of 4.00 + 5.50 equalling to 9.50 it would read 04.0005.50.
function calculate() {
var total = 0;
$('input.calc').each(function() {
var num = this.value;
//Number(this.value, 10);
if (!isNaN(num)) {
total += num.toFixed(2);
}
});
$("#total").val(total);
}
Any help its appreciated, Thanks
<script language="javascript">
function calculate() {
var total = 0;
$('input.calc').each(function() {
var num = this.value;
//Number(this.value, 10);
if (!isNaN(num)) {
total += num.parseFloat(num);
}
});
$("#total").val(total);
}
</script>
function calculate() {
var total = 0;
$('input.calc').each(function() {
var num = parseFloat(this.value);
//Number(this.value, 10);
if (!isNaN(num)) {
total += num;
}
});
$("#total").val(total);
}
I have used a jsFiddle that I found on another question on here that will work perfectly if I can get the subtotal to multiply instead of addition.
I am sure this is a really easy fix, but I'm struggling to make the change.
Can someone help me please?
Thank you in advance
http://jsfiddle.net/77uxK/48/
$(document).ready(function(){
var sum = 0;
function calcSum(prevVal){
sum = sum - prevVal + (this.value/1);
return sum;
}
var subAmt = $("#sub"), taxAmt = $("#tax"), totAmt = $("#total");
$(".val").each(function(){
var prevVal = this.value/1, self = this;
$(this).keyup(function(){
subAmt.val(calcSum.call(self, prevVal));
totAmt.val(sum + sum*parseFloat(taxAmt.val()/100));
prevVal = self.value;
});
});
});
just change the function to
function calcSum(prevVal) {
var val1 = $('#val1').val();
var val2 = $('#val2').val();
sum = parseInt(val1) * parseInt(val2); // parseFloat based on your need change it
return sum;
}
jsfiddle link