</form>
<script type="text/javascript">
- <!--//
- function calculate_qty() {
- [% FOREACH row = VARIABLES %]
- var [% row.name %] = document.getElementsByName("[% row.name %]")[0].value.replace(/,/g, ".");
- [% END %]
- var result = [% formel %];
- result = number_format(result, 2, ",", ".");
- window.opener.document.getElementsByName(document.Form.input_name.value)[0].value = result;
- self.close();
- }
- //-->
+ function calculate_qty() {
+[%- FOREACH row = VARIABLES %]
+ var [% row.name %] = parse_amount('[% myconfig.numberformat %]', document.getElementsByName("[% row.name %]")[0].value);
+[%- END %]
+ var result = [% formel %];
+ result = number_format(result, 2, '[% myconfig.numberformat %]');
+ window.opener.document.getElementsByName(document.Form.input_name.value)[0].value = result;
+ self.close();
+ }
+
+ function parse_amount(numberformat, amount) {
+ if (numberformat == '1.000,00' || numberformat == '1000,00')
+ amount = amount.replace(/\./g, "").replace(/,/, ".");
+ if (numberformat == "1'000.00")
+ amount = amount.replace(/\'/g, '');
+ return amount.replace(/,/g, '');
+ }
-function /*out: String*/ number_format( /* in: float */ number,
- /* in: integer */ laenge,
- /* in: String */ sep,
- /* in: String */ th_sep ) {
+ function number_format(number, precision, numberformat) {
+ number = Math.round( number * Math.pow(10, precision) ) / Math.pow(10, precision);
+ var nf = numberformat.replace(/\d/g, '').split('').reverse();
+ var sep = nf[0];
+ var th_sep = nf[1];
- number = Math.round( number * Math.pow(10, laenge) ) / Math.pow(10, laenge);
- str_number = number+"";
- arr_int = str_number.split(".");
- if(!arr_int[0]) arr_int[0] = "0";
- if(!arr_int[1]) arr_int[1] = "";
- if(arr_int[1].length < laenge){
- nachkomma = arr_int[1];
- for(i=arr_int[1].length+1; i <= laenge; i++){ nachkomma += "0"; }
- arr_int[1] = nachkomma;
- }
- if(th_sep != "" && arr_int[0].length > 3){
- Begriff = arr_int[0];
- arr_int[0] = "";
- for(j = 3; j < Begriff.length ; j+=3){
- Extrakt = Begriff.slice(Begriff.length - j, Begriff.length - j + 3);
- arr_int[0] = th_sep + Extrakt + arr_int[0] + "";
- }
- str_first = Begriff.substr(0, (Begriff.length % 3 == 0)?3:(Begriff.length % 3));
- arr_int[0] = str_first + arr_int[0];
- }
- return arr_int[0]+sep+arr_int[1];
-}
+ str_number = number+"";
+ arr_int = str_number.split(".");
+ if(!arr_int[0]) arr_int[0] = "0";
+ if(!arr_int[1]) arr_int[1] = "";
+ if(arr_int[1].length < precision) {
+ nachkomma = arr_int[1];
+ for(i=arr_int[1].length+1; i <= precision; i++) {
+ nachkomma += "0";
+ }
+ arr_int[1] = nachkomma;
+ }
+ if(th_sep != "" && arr_int[0].length > 3) {
+ raw_arr_int = arr_int[0];
+ arr_int[0] = "";
+ for(j = 3; j < raw_arr_int.length ; j+=3) {
+ arr_int[0] = th_sep + raw_arr_int.slice(raw_arr_int.length - j, raw_arr_int.length - j + 3) + arr_int[0] + "";
+ }
+ str_first = raw_arr_int.substr(0, (raw_arr_int.length % 3 == 0) ? 3 : (raw_arr_int.length % 3));
+ arr_int[0] = str_first + arr_int[0];
+ }
+ return arr_int[0] + sep + arr_int[1];
+ }
</script>
</body>