Commit 3dee7293 authored by Christopher Guess's avatar Christopher Guess
Browse files

fixed test suite class so it work, added commas for large numbers

parent 9b825305
......@@ -103,8 +103,8 @@ Marka.prototype.doConversions = function() {
var node = $(value);
var children = node.children()
self.getValueInSetCurrency(res.number, res.symbol, function(value, converted) {
if (converted == true) {
node.html(value.toFixed(0) + " " + self.getCurrentCurrency() + " ");
if (converted == true) {
node.html(getFormattedCurrency(value) + " " + self.getCurrentCurrency() + " ");
node.append(children);
node.children(".marka-dropdown").html("<span class=\"marka-result\">" + node.data("original_value") + "</span>")
} else {
......@@ -117,6 +117,23 @@ Marka.prototype.doConversions = function() {
});
}
// From http://stackoverflow.com/a/33808863/604031
function getFormattedCurrency(num) {
num += '';
num = parseFloat(num).toFixed(2);
var x = num.split('.');
var x1 = x[0];
var x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
var merged = x1 + x2;
return merged;
}
Marka.prototype.splitSymbols = function(text) {
var numbers = /[\d,.]+/;
try {
......
......@@ -10,7 +10,7 @@
<body>
<h1>Testing formats</h1>
<div id="test">
<div id="articles">
<h2>Should be caught:</h2>
<ul>
<li>400 USD</li>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment