本文整理汇总了C++中Currency::to方法的典型用法代码示例。如果您正苦于以下问题:C++ Currency::to方法的具体用法?C++ Currency::to怎么用?C++ Currency::to使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Currency
的用法示例。
在下文中一共展示了Currency::to方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: totalTransactions
// Read in a csv file containing transactions in the following format:
// location,item_sku,sales_amount currency_code
// Total all sales for a given item_sku in the requested currency
double totalTransactions(QString filename, QString item, QString currency) {
// for each line, split, if matches item, get currency, convert, add to total
double sum = 0.0;
QFile csv(filename);
csv.open(QIODevice::ReadOnly);
while (true) {
QString line = csv.readLine();
if (line.isEmpty())
break;
QStringList split = line.split(QRegExp("[, \n]"));
if (split.size() < 4 || split[1] != item)
continue;
bool ok = false;
double amount = split[2].toDouble(&ok);
Currency *c = Currency::get(split[3]);
if (!ok) {
qDebug() << "Failed to parse amount:" << split[2];
continue;
}
if (!c)
continue;
sum += roundToEven(amount * c->to(currency) * 100.0) / 100.0;
}
return sum;
}