<commit_before>/**
 * Created by gkt on 5/18/15.
 */

package scalatddpackt

import math.{abs, pow}

package object money {

  def getMoney(dollars: Long, cents: Long, precision : Int): Money = {
    require(precision > 0)
    val decimalMultiplier = math.pow(10, precision).toLong
    if (dollars < 0 || cents < 0)
      Money(-(decimalMultiplier * abs(dollars) + abs(cents)), precision)
    else
      Money(decimalMultiplier * dollars + cents, precision)
  }

  // TODO: Allow for money to be constructed from any level of precision
  def getDecimalMoney(dollars: Double, precision : Int): Money = {
    require(precision > 0)
    val decimalMultiplier = math.pow(10, precision).toLong // DRY (fix later)
    val doubleFudgeFactor = 49 / math.pow(10, precision + 2)
    print(s"multipler $decimalMultiplier and fudge $doubleFudgeFactor")
    val sign = if (dollars < 0) -1 else 1
    val cents = decimalMultiplier * (abs(dollars) + doubleFudgeFactor)
    Money(sign * cents.toLong, precision)
  }

  case class Money(cents: Long, precision : Int) extends Ordered[Money] {

    require(precision > 0)

    def decimalMultiplier = math.pow(10, precision).toLong

    def dollarsOnly = cents / decimalMultiplier
<commit_msg>clean up and addition of a convenience method for US dollars<commit_after>/**
 * Created by gkt on 5/18/15.
 */

package scalatddpackt

import math.{abs, pow}

package object money {

  def getMoney(dollars: Long, cents: Long, precision : Int): Money = {
    require(precision > 0)
    val decimalMultiplier = math.pow(10, precision).toLong
    if (dollars < 0 || cents < 0)
      Money(-(decimalMultiplier * abs(dollars) + abs(cents)), precision)
    else
      Money(decimalMultiplier * dollars + cents, precision)
  }

  // TODO: Allow for money to be constructed from any level of precision
  def getDecimalMoney(dollars: Double, precision : Int): Money = {
    require(precision > 0)
    val decimalMultiplier = math.pow(10, precision).toLong // DRY (fix later)
    val doubleFudgeFactor = 49 / math.pow(10, precision + 2)
    val sign = if (dollars < 0) -1 else 1
    val cents = decimalMultiplier * (abs(dollars) + doubleFudgeFactor)
    Money(sign * cents.toLong, precision)
  }

  def getUSAMoney(dollars : Double) = getDecimalMoney(dollars, 2)

  case class Money(cents: Long, precision : Int) extends Ordered[Money] {

    require(precision > 0)

    def decimalMultiplier = math.pow(10, precision).toLong

    def dollarsOnly = cents / decimalMultiplier

{'fraction_non_alphanumeric': 0.10803212851405622, 'fraction_numerical': 0.01967871485943775, 'mean_word_length': 3.579044117647059, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4197344', 'n_tokens_mistral': 833, 'n_tokens_neox': 769, 'n_words': 238}