Skip to content

Commit

Permalink
Merge pull request #39 from ImMin5/master
Browse files Browse the repository at this point in the history
Modify str to float convert method
  • Loading branch information
ImMin5 authored Nov 1, 2023
2 parents d981925 + ab1bc48 commit 034d3d2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/cloudforet/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import json
import time

from decimal import Decimal
from datetime import datetime, timedelta, timezone
from spaceone.core.error import *
from spaceone.core.manager import BaseManager
Expand Down Expand Up @@ -70,8 +70,8 @@ def _make_cost_data(self, results, end, options, tenant_id=None):

def _make_data_info(self, result, billed_date, options, tenant_id=None):
additional_info = self._get_additional_info(result, options, tenant_id)
cost = self._convert_str_to_float_format(result.get('costinbillingcurrency', 0))
usage_quantity = self._convert_str_to_float_format(result.get('quantity', 0))
cost = self._convert_str_to_float_format(result.get('costinbillingcurrency', 0.0))
usage_quantity = self._convert_str_to_float_format(result.get('quantity', 0.0))
usage_type = result.get('metername', '')
usage_unit = str(result.get('unitofmeasure', ''))
region_code = self._get_region_code(result.get('resourcelocation', ''))
Expand Down Expand Up @@ -242,8 +242,11 @@ def _set_product_from_benefit_name(benefit_name):
return product_name

@staticmethod
def _convert_str_to_float_format(num_str: str):
return float(num_str)
def _convert_str_to_float_format(num_str) -> float or Decimal:
if isinstance(num_str, float):
return num_str
else:
return Decimal(str(num_str))

@staticmethod
def _set_billed_date(start):
Expand Down

0 comments on commit 034d3d2

Please sign in to comment.