You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@doris.apache.org by GitBox <gi...@apache.org> on 2019/04/29 02:09:23 UTC

[GitHub] [incubator-doris] imay commented on a change in pull request #1064: Add money_format function

imay commented on a change in pull request #1064: Add money_format function
URL: https://github.com/apache/incubator-doris/pull/1064#discussion_r279225597
 
 

 ##########
 File path: be/src/exprs/string_functions.cpp
 ##########
 @@ -707,4 +708,45 @@ StringVal StringFunctions::parse_url_key(
     return result_sv;
 }
 
+StringVal StringFunctions::money_format(FunctionContext* context, const DoubleVal& v) {
+    if (v.is_null) {
+        return StringVal::null();
+    }
+
+    double v_cent= MathFunctions::my_double_round(v.val, 2, false, false) * 100;
+    return do_money_format(context, std::to_string(v_cent));
+}
+
+StringVal StringFunctions::money_format(FunctionContext *context, const DecimalVal &v) {
+    if (v.is_null) {
+        return StringVal::null();
+    }
+
+    DecimalValue rounded;
+    DecimalValue::from_decimal_val(v).round(&rounded, 2, HALF_UP);
+    DecimalValue tmp(std::string("100"));
+    DecimalValue result = rounded * tmp;
+    return do_money_format(context, result.to_string());
+}
+
+StringVal StringFunctions::money_format(FunctionContext *context, const BigIntVal &v) {
+    if (v.is_null) {
+        return StringVal::null();
+    }
+
+    std::string cent_money = std::to_string(v.val) + std::string("00");
+    return do_money_format(context, cent_money);
+}
+
+StringVal StringFunctions::money_format(FunctionContext *context, const LargeIntVal &v) {
+    if (v.is_null) {
+        return StringVal::null();
+    }
+
+    std::stringstream ss;
+    ss << v.val;
+    std::string cent_money = ss.str() + std::string("00");
 
 Review comment:
   ```suggestion
       ss << v.val << ".00";
       std::string cent_money = ss.str();
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org