From 5f8dd8011ae7c5a2866545b118d07f3dd15da287 Mon Sep 17 00:00:00 2001
From: Fernando Erd <fce15@inf.ufpr.br>
Date: Tue, 24 Oct 2017 10:41:26 -0200
Subject: [PATCH] Round Pib Per Capita

---
 src/libs/routes/pibpercapita.js | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/libs/routes/pibpercapita.js b/src/libs/routes/pibpercapita.js
index b0ef35cc..5fd9bd79 100644
--- a/src/libs/routes/pibpercapita.js
+++ b/src/libs/routes/pibpercapita.js
@@ -163,6 +163,21 @@ pibpercapitaApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
       .order('ibge_pib.ano_censo')
    }
    next();
-}, rqf.build(), query, id2str.transform(false), response('pibpercapita'));
+}, query, id2str.transform(false), (req, res, next) => {
+     req.result.forEach((i) => {
+         let value = i.total;
+         let res = value.toString().split(".");
+         //rounding decimal.
+         let decimal = Math.round(res[1].toString().substring(0,2) + (".") + res[1].toString().substring(2,3));
+         //case 0 after comma
+         if (res[1].toString().substring(0,1) == 0) {
+              i.total = parseFloat(res[0] + "." + "0" + decimal);
+         } else {
+         i.total = parseFloat(res[0] + "." +  decimal);
+       }
+     });
+     next();
+ } ,response("pibpercapita"));
+
 
 module.exports = pibpercapitaApp;
-- 
GitLab