How can i program this, the decimal shift needs to be programed that most of it I think , the rest would be just a normal add, any thoughts on how to program this? This is for an incrementer I'm building, the user can press plus or minus and increment a text input.
A:
You can use:
HTML
<input id="value" type="text" value="0">
<input id="right" type="button" value="+">
<input id="left" type="button" value="-">
JS (with jquery)
$("#right").click(function(){
$("#value").val($("#value").val() * 10);
});
$("#left").click(function(){
$("#value").val($("#value").val() / 10);
});
Topera
2010-08-13 02:01:25
yes but it needs to show like this: 10,00 so you can add 10,25 + 100,10 for example
tada
2010-08-13 02:04:54
Sorry, but still confusing...
Topera
2010-08-13 02:06:13
it's addition but with comma , i need to show and add monetary values , so theres a need to program the comma shifting
tada
2010-08-13 02:09:17
If you want a button to shift comma to rigth or left, you need just multiply by 10 ou divide by 10. I'll edit my aswser.
Topera
2010-08-13 02:14:51
it's not a button, the shift needs to be programed, it's automatical just like in a normal calculator
tada
2010-08-13 02:18:16
Sorry, but I don't understand. If you sum 3.1 with 10.12, you will have 13.22. You don't need to program comma shift... :(
Topera
2010-08-13 02:22:42
@tada your request is very confusing - can you indicate all the input elements + buttons you have and a few sample additions you want to accomplish? (edit this information and add it to the original question)
scunliffe
2010-08-13 02:27:45
@Topera , true, thanks for your help.@scunliffe, I think i found a solution.regards.
tada
2010-08-14 07:53:33
A:
I assume you're referring to the use of a comma , as a decimal separator instead of a ..
If there are no other commas used as separators in the number (I don't know what is used for thousand separators in that case), then you could try something like this:
Try it out: http://jsfiddle.net/yuEAs/
HTML
<input id='one' type='text' value='12,34' /><br>
<input id='two' type='text' value='43,21' /><br>
<input id='result' type='text' /><br>
<div id='click'>Click to add</div>
jQuery
$('#click').click(function() {
// Replace comma separators with point separators, and parseFloat the result
var one = parseFloat($('#one').val().replace(',','.'));
var two = parseFloat($('#two').val().replace(',','.'));
// Add the numbers
var result = one + two;
// Convert the result to a string, and revert the decimal separator back
$('#result').val( result.toString().replace('.',',') );
});
I don't have any experience with this, so maybe there's a better way.
patrick dw
2010-08-13 02:54:06