We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
https://free.currencyconverterapi.com/api/v6/convert?q=USD_CNY
function format_fiat(val) { if (val >= 100000 || val == 0) { val = Formatter.toLocaleString(Math.round(val)); } else if (val >= 1) { val = Formatter.toLocaleString(val, { minDecimalPlaces: 2, maxDecimalPlaces: 2 }); } else if (val < 0.000001) { val = Number(val).toExponential(2) } else { val = Formatter.toLocaleString(val, { minDecimalPlaces: 6, maxDecimalPlaces: 6 }); } return val; }
function format_crypto(val) { return format_crypto_helper(val, 0.00000001, 3, 8, 8) } function format_crypto_helper(val, expenonentialThreshold, exponentialDigits, minDecimalPlaces, maxDecimalPlaces) { if (val >= 1000 || val == 0) { val = Formatter.toLocaleString(Math.round(val)); } else if (val >= 1) { val = Formatter.toLocaleString(val, { minDecimalPlaces: minDecimalPlaces, maxDecimalPlaces: maxDecimalPlaces }); } else { if (val < expenonentialThreshold) { val = Number(val).toExponential(exponentialDigits) } else { val = Formatter.toLocaleString(val, { minDecimalPlaces: minDecimalPlaces, maxDecimalPlaces: maxDecimalPlaces }); } } return val; } function format_crypto_graph_label(val) { return format_crypto_helper(val, 0.00000001, 3, 2, 8) } function format_crypto_short(val) { return format_crypto_helper(val, 0.01, 1, 2, 2) }
var Formatter = (function() { var _locale = Cookies.get('_locale') || undefined; var supportsLocaleOptions = !!(typeof Intl == 'object' && Intl && typeof Intl.NumberFormat == 'function'); var _toLocaleString = function(val) { if (supportsLocaleOptions) { return val.toLocaleString(_locale); } return val.toLocaleString(); }; var _toLocaleStringWithDecimalPlaces = function(val, minDecimalPlaces, maxDecimalPlaces) { if (supportsLocaleOptions) { return val.toLocaleString(_locale, { minimumFractionDigits: minDecimalPlaces, maximumFractionDigits: maxDecimalPlaces }); } return val.toFixed(maxDecimalPlaces); }; var toLocaleString = function(value, options) { var num = Number(value); if (isNaN(num)) { return value; } var minDecimalPlaces = options && options.minDecimalPlaces; var maxDecimalPlaces = options && options.maxDecimalPlaces; if (minDecimalPlaces === undefined || maxDecimalPlaces === undefined) { return _toLocaleString(num); } return _toLocaleStringWithDecimalPlaces(num, minDecimalPlaces, maxDecimalPlaces); } return { toLocaleString: toLocaleString }; } )();
coinmarketcap
var tickerData = {}; var apiDomain = "https://api.coinmarketcap.com"; $.ajax({ url: apiDomain + "/v1/ticker/?limit=0", }).done(function( data ) { //Load Crypto Rates 加密货币 for (i=0; i < data.length; i++) { tickerData[data[i]['id']] = data[i]['price_usd']; } //Load Fiat Rates 法定汇率(暂不考虑此汇率) var fiatRates = $("#currency-exchange-rates").data(); for (currency in fiatRates) { tickerData["__fiat-" + currency] = fiatRates[currency] } // 业务逻辑,开始转换啦! convert(); }).fail(function( data ) { console.error(data); });
function convert() { var form = getFormValues(); var fromId = form.fromId; // "ethereum" var fromName = form.fromName; // "Ethereum (ETH)" var toId = form.toId; // "bitcny" var toName = form.toName; // "bitCNY (BITCNY)" var conversionAmount = form.conversionAmount; // 1 if (isNaN(conversionAmount) || conversionAmount == "") { conversionAmount = 0; } conversionAmount = parseFloat(conversionAmount); var fromAmount = tickerData[fromId]; // "ethereum" var toAmount = tickerData[toId]; // "bitcny" var convertedAmount = conversionAmount * fromAmount / toAmount; // convertedAmount = 1389.3264952911668, conversionAmount = 1 if (toId.substring(0,6) == "__fiat") { convertedAmount = format_fiat(convertedAmount); } else { convertedAmount = format_crypto(convertedAmount); convertedAmount = "1,389" } var resultLeft = conversionAmount + " " + fromName; $('#conversion-result-left').html(resultLeft); $('#conversion-result-value').html(convertedAmount); $('#conversion-result-value-currency').html(toName); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
https://free.currencyconverterapi.com/api/v6/convert?q=USD_CNY
算法函数
业务代码
coinmarketcap
接口,获取加密货币信息The text was updated successfully, but these errors were encountered: