Punkt in Komme umwandeln

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Punkt in Komme umwandeln

    Hallo zusammen,

    ich habe folgenden JS Code, der als Paypal Gebührenrechner fungiert. Das Ergebnis am Ende wird aber leider als Punkt und nicht als Kommaversion ausgegeben, also 500.90€ anstatt 500,90€. Hier die Website mit dem Rechner, falls euch das hilft: gebuehrenrechner.com/paypal-gebuehrenrechner/

    Hier der Code:

    Source Code

    1. function get_float(string) {
    2. var to_return = parseFloat(string);
    3. if (typeof to_return == 'undefined') {
    4. to_return = 0,00
    5. }
    6. if (isNaN(to_return)) {
    7. to_return = 0,00
    8. }
    9. to_return = (to_return / 100) * 100;
    10. return to_return
    11. }
    12. function get_key_code(e) {
    13. if (typeof e == "undefined") {
    14. e = window.event
    15. }
    16. if (e.keyCode) {
    17. return e.keyCode
    18. } else if (e.which) {
    19. return e.which
    20. } else {
    21. return e.charCode
    22. }
    23. }
    24. function has_selection(ele) {
    25. var txt = '',
    26. len = 0,
    27. start = 0,
    28. end = 0;
    29. if (document.selection) {
    30. txt = document.selection.createRange().text
    31. } else if (window.getSelection) {
    32. txt = window.getSelection()
    33. } else if (document.getSelection) {
    34. txt = document.getSelection()
    35. } else {
    36. return false
    37. }
    38. if (ele.selectionStart) {
    39. start = ele.selectionStart
    40. }
    41. if (ele.selectionEnd) {
    42. end = ele.selectionEnd
    43. }
    44. len = end - start;
    45. if (len > 0) {
    46. return true
    47. } else if (typeof txt == "undefined") {
    48. return false
    49. } else if (isNaN(txt)) {
    50. return false
    51. } else if (txt.length > 0) {
    52. return true
    53. } else {
    54. return false
    55. }
    56. }
    57. function textbox_onkeypress(e) {
    58. if (typeof e == "undefined") {
    59. e = window.event
    60. }
    61. var keycode = get_key_code(e);
    62. var to_return = true;
    63. switch (keycode) {
    64. case 8:
    65. break;
    66. case 9:
    67. break;
    68. case 13:
    69. break;
    70. case 37:
    71. case 39:
    72. break;
    73. case 38:
    74. if (this.value != '') {
    75. this.value = (get_float(this.value) + 0,5).toFixed(2)
    76. }
    77. break;
    78. case 40:
    79. if (get_float(this.value) >= 0,5) {
    80. this.value = (get_float(this.value) - 0,5).toFixed(2)
    81. } else {
    82. this.value = '0,00'
    83. }
    84. if (this.id == 'to_receive') {
    85. rp_calc()
    86. } else if (this.id == 'if_you_receive') {
    87. p_calc()
    88. }
    89. break;
    90. case 46:
    91. if (this.value.indexOf(",") != -1) {
    92. if (has_selection(this) == false) {
    93. to_return = false
    94. }
    95. }
    96. break;
    97. case 48:
    98. case 49:
    99. case 50:
    100. case 51:
    101. case 52:
    102. case 53:
    103. case 54:
    104. case 55:
    105. case 56:
    106. case 57:
    107. if ((this.id != 'paypal_fee_percent')) {
    108. if (this.value.length >= 3) {
    109. if (this.value.substr(this.value.length - 3, 1) == ',') {
    110. if (has_selection(this) == false) {
    111. to_return = false
    112. }
    113. }
    114. }
    115. }
    116. break;
    117. default:
    118. to_return = false
    119. }
    120. if ((!e.which) && (keycode == 46)) {
    121. to_return = true
    122. }
    123. if ((typeof e.which == "undefined") && (keycode == 46) && (this.value.indexOf(",") != -1) && (has_selection(this) == false)) {
    124. to_return = false
    125. }
    126. e.returnValue = to_return;
    127. return to_return
    128. }
    129. function set_rate(percent, fixed, sign, name) {
    130. document.forms['ppc'].elements['paypal_fee_percent'].value = percent;
    131. document.forms['ppc'].elements['paypal_fee_fixed'].value = fixed;
    132. document.getElementById('currency_sign').innerHTML = sign;
    133. document.getElementById('currency_name').innerHTML = name;
    134. document.getElementById('currency_symbol_1').innerHTML = sign;
    135. document.getElementById('currency_symbol_2').innerHTML = sign;
    136. document.getElementById('currency_symbol_3').innerHTML = sign;
    137. document.getElementById('currency_symbol_4').innerHTML = sign;
    138. document.getElementById('currency_symbol_5').innerHTML = sign
    139. }
    140. function figure_fees(item_price, fee_percentage, fixed_fee) {
    141. var the_fee_percentage = fee_percentage / 100;
    142. the_fee_percentage = the_fee_percentage.toFixed(4);
    143. the_fee_percentage = get_float(the_fee_percentage);
    144. var to_return = item_price * the_fee_percentage + fixed_fee;
    145. to_return = Math.round(to_return * 100) / 100;
    146. to_return = to_return.toFixed(2);
    147. to_return = get_float(to_return);
    148. if (to_return > item_price) {
    149. to_return = item_price
    150. }
    151. return to_return
    152. }
    153. function p_calc() {
    154. if (document.forms['ppc'].elements['if_you_receive'].value != '') {
    155. var amount_sent = get_float(document.forms['ppc'].elements['if_you_receive'].value);
    156. if (amount_sent == 0) {
    157. document.forms['ppc'].elements['paypal_fees'].value = document.forms['ppc'].elements['you_would_receive'].value = '0,00'
    158. } else {
    159. var the_paypal_fees = figure_fees(amount_sent, get_float(document.forms['ppc'].elements['paypal_fee_percent'].value), get_float(document.forms['ppc'].elements['paypal_fee_fixed'].value));
    160. document.forms['ppc'].elements['paypal_fees'].value = the_paypal_fees.toFixed(2);
    161. var amount_after_fees = amount_sent - get_float(document.forms['ppc'].elements['paypal_fees'].value);
    162. if (amount_after_fees < 0) {
    163. amount_after_fees = 0
    164. }
    165. document.forms['ppc'].elements['you_would_receive'].value = amount_after_fees.toFixed(2)
    166. }
    167. } else {
    168. document.forms['ppc'].elements['paypal_fees'].value = '';
    169. document.forms['ppc'].elements['you_would_receive'].value = ''
    170. }
    171. }
    172. function rp_calc(src) {
    173. if (document.forms['ppc'].elements['to_receive'].value != '') {
    174. var desired_amount = get_float(document.forms['ppc'].elements['to_receive'].value);
    175. if (desired_amount == 0) {
    176. document.forms['ppc'].elements['a_person_would'].value = '0,00'
    177. } else {
    178. var a_person_must_send = (desired_amount + get_float(document.forms['ppc'].elements['paypal_fee_fixed'].value)) / (1 - (get_float(document.forms['ppc'].elements['paypal_fee_percent'].value) / 100).toFixed(4));
    179. document.forms['ppc'].elements['a_person_would'].value = a_person_must_send.toFixed(2);
    180. document.forms['ppc'].elements['if_you_receive'].value = document.forms['ppc'].elements['a_person_would'].value;
    181. p_calc()
    182. }
    183. } else {
    184. if (src != 1) {
    185. document.forms['ppc'].elements['a_person_would'].value = '';
    186. document.forms['ppc'].elements['if_you_receive'].value = ''
    187. }
    188. p_calc()
    189. }
    190. }
    191. if (window.addEventListener) {
    192. window.addEventListener("load", window_onload, false)
    193. } else if (window.attachEvent) {
    194. window.attachEvent("onload", window_onload)
    195. }
    196. function window_onload() {
    197. document.forms['ppc'].elements['to_receive'].onkeypress = textbox_onkeypress;
    198. document.forms['ppc'].elements['if_you_receive'].onkeypress = textbox_onkeypress;
    199. document.forms['ppc'].elements['paypal_fee_percent'].onkeypress = textbox_onkeypress;
    200. document.forms['ppc'].elements['paypal_fee_fixed'].onkeypress = textbox_onkeypress;
    201. document.forms['ppc'].elements['to_receive'].onkeyup = rp_calc;
    202. document.forms['ppc'].elements['if_you_receive'].onkeyup = p_calc;
    203. document.forms['ppc'].elements['to_receive'].focus()
    204. }
    Display All
    Ich hoffe jemand kann mir helfen :)
  • Nächster Code, selbes Problem... Habe selbst schon ein bisschen rumprobiert, bekomme es aber leider nicht hin..

    Vielleicht kann nochmal jemand helfen? :)

    JavaScript Source Code

    1. function berechnen() {
    2. 'use strict';
    3. var p = parseFloat(window.document.rechner.zahlung.value),
    4. t = window.document.rechner.zahlungsart.value,
    5. c,
    6. o;
    7. switch (t) {
    8. case '1':
    9. c = (p * 0.019) + 0.35;
    10. break;
    11. case '2':
    12. c = 0;
    13. break;
    14. case '3':
    15. c = (p * 0.015) + 0.35;
    16. break;
    17. case '4':
    18. c = (p * 0.10) + 0.10;
    19. break;
    20. case '5':
    21. c = (p * 0.017) + 0.35;
    22. break;
    23. case '6':
    24. c = (p * 0.015) + 0.35;
    25. break;
    26. }
    27. if (p === 0.00) {
    28. o = 0.00; c = 0.00;
    29. } else {
    30. o = parseFloat(p - c);
    31. }
    32. window.document.ergebnis.out_gebuehren.value = c.toFixed(2) + ' \u20AC';
    33. window.document.ergebnis.out_rest.value = o.toFixed(2) + ' \u20AC';
    34. }
    Display All