当前位置: 首页>>代码示例>>Scala>>正文


Scala BigDecimal类代码示例

本文整理汇总了Scala中scala.math.BigDecimal的典型用法代码示例。如果您正苦于以下问题:Scala BigDecimal类的具体用法?Scala BigDecimal怎么用?Scala BigDecimal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BigDecimal类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: TextNetSpec

//设置package包名称以及导入依赖的类
package applicant.ml.rnn

import org.scalatest.FlatSpec
import org.scalatest.MustMatchers._
import org.scalatest.PrivateMethodTester._

import scala.math.BigDecimal


class TextNetSpec extends FlatSpec {
    "adjustCreativity" must "adjust creativity non-linearly" in {
        val textnet = new TextNet(null)

        val adjustCreativity = PrivateMethod[Array[Double]]('adjustCreativity)

        var results = textnet invokePrivate adjustCreativity(Array[Double](0.7, 0.2, 0.1), 1.0)
        results = results.map(x => BigDecimal(x).setScale(2, BigDecimal.RoundingMode.HALF_UP).toDouble)
        results must equal (Array[Double](0.7, 0.2, 0.1))

        results = textnet invokePrivate adjustCreativity(Array[Double](0.7, 0.2, 0.1), 0.7)
        results = results.map(x => BigDecimal(x).setScale(2, BigDecimal.RoundingMode.HALF_UP).toDouble)
        results must equal (Array[Double](0.81, 0.14, 0.05))

        results = textnet invokePrivate adjustCreativity(Array[Double](0.7, 0.2, 0.1), 0.3)
        results = results.map(x => BigDecimal(x).setScale(2, BigDecimal.RoundingMode.HALF_UP).toDouble)
        results must equal (Array[Double](0.98, 0.02, 0.0))
    }
} 
开发者ID:dataworks,项目名称:internship-2016,代码行数:29,代码来源:TextNetSpec.scala

示例2: MarketEodEvent

//设置package包名称以及导入依赖的类
package alpha.models.events

import alpha.models.Ticker
import com.github.nscala_time.time.Imports._
import org.joda.time.format.ISODateTimeFormat

import scala.math.BigDecimal
import scala.util.Try

case class MarketEodEvent(
                           ticker: Ticker,
                           date: DateTime,
                           open: BigDecimal,
                           high: BigDecimal,
                           low: BigDecimal,
                           close: BigDecimal,
                           volume: BigDecimal,
                           exDividend: BigDecimal,
                           splitRatio: BigDecimal,
                           adjustedOpen: BigDecimal,
                           adjustedHigh: BigDecimal,
                           adjustedLow: BigDecimal,
                           adjustedClose: BigDecimal,
                           adjustedVolume: BigDecimal
                           ) extends MarketEvent


object MarketEodEvent {
  def fromSequenceOfString(line: Seq[String]): Option[MarketEodEvent] = line match {
    case List(ticker, date, open, high, low, close, volume, exDividend, splitRatio, adjustedOPen, adjustedHigh, adjustedLow, adjustedClose, adjustedVolume) =>
      Try(
        MarketEodEvent(
          Ticker(ticker),
          dateFromString(date),
          BigDecimal(open),
          BigDecimal(high),
          BigDecimal(low),
          BigDecimal(close),
          BigDecimal(volume),
          BigDecimal(exDividend),
          BigDecimal(splitRatio),
          BigDecimal(adjustedOPen),
          BigDecimal(adjustedHigh),
          BigDecimal(adjustedLow),
          BigDecimal(adjustedClose),
          BigDecimal(adjustedVolume)
        )
      ).toOption
    case _ =>
      None
  }
  def dateFromString(string: String): DateTime = {
    val fmt = ISODateTimeFormat.yearMonthDay()
    fmt.parseDateTime(string)
  }

} 
开发者ID:kszlim,项目名称:scala-alpha,代码行数:58,代码来源:MarketEodEvent.scala

示例3: ItemDaoDoobieSpec

//设置package包名称以及导入依赖的类
package daos.doobie

import doobie.specs2.imports.AnalysisSpec
import org.specs2.mutable.Specification
import testutil.TestUtil
import scala.math.BigDecimal

object ItemDaoDoobieSpec extends Specification with AnalysisSpec {
  val transactor = TestUtil.transactor()

  import DaoItemDoobie._

  check(qAdd(0L, BigDecimal(0), ""))
  check(qAddByServicio(0L, 0L))
  check(qDatosCliente(0L))
  check(qMascotas(0L))
  check(qCliente(0L))
  check(qTelefonos(0L))
  check(qById(0L))
  check(qEditar(0L, BigDecimal("0"), ""))
} 
开发者ID:kdoomsday,项目名称:kaminalapp,代码行数:22,代码来源:ItemDaoDoobieSpec.scala

示例4: CommandsTest

//设置package包名称以及导入依赖的类
package cqrs.commands

import java.time.{LocalDateTime, OffsetDateTime, ZoneOffset}
import java.util.UUID

import akka.stream.Materializer
import org.scalatest.{AsyncFreeSpec, BeforeAndAfterAll}
import endpoints.play.client.{CirceEntities, Endpoints}
import play.api.libs.ws.ahc.{AhcWSClient, AhcWSClientConfig}
import play.core.server.NettyServer

import scala.concurrent.Future
import scala.math.BigDecimal

class CommandsTest extends AsyncFreeSpec with BeforeAndAfterAll {

  private val server = NettyServer.fromRouter()(Commands.routes)

  implicit val materializer: Materializer = server.materializer
  private val wsClient = AhcWSClient(AhcWSClientConfig())

  object client
    extends Endpoints("http://localhost:9000", wsClient)
      with CirceEntities
      with CommandsEndpoints

  override def afterAll(): Unit = {
    server.stop()
    wsClient.close()
  }

  "Commands" - {

    val arbitraryDate = OffsetDateTime.of(LocalDateTime.of(2017, 1, 8, 12, 34, 56), ZoneOffset.UTC).toInstant
    val arbitraryValue = BigDecimal(10)

    "create a new meter" in {
      client.command(CreateMeter("electricity")).map { maybeEvent =>
        assert(maybeEvent.collect { case StoredEvent(_, MeterCreated(_, "electricity")) => () }.nonEmpty)
      }
    }
    "create a meter and add readings to it" in {
      for {
        maybeCreatedEvent <- client.command(CreateMeter("water"))
        id <-
          maybeCreatedEvent
            .collect { case StoredEvent(_, MeterCreated(id, _)) => id }
            .fold[Future[UUID]](Future.failed(new NoSuchElementException))(Future.successful)
        maybeAddedEvent <- client.command(AddRecord(id, arbitraryDate, arbitraryValue))
        _ <-
          maybeAddedEvent
            .collect { case StoredEvent(_, RecordAdded(`id`, `arbitraryDate`, `arbitraryValue`)) => () }
            .fold[Future[Unit]](Future.failed(new NoSuchElementException))(Future.successful)
      } yield assert(true)
    }
  }

} 
开发者ID:julienrf,项目名称:endpoints,代码行数:59,代码来源:CommandsTest.scala

示例5: ULong

//设置package包名称以及导入依赖的类
package net.karana.unsigned

import scala.math.BigDecimal

object ULong {
  implicit def toULong(byte: Long) = ULong(byte)
}

case class ULong(val long: Long) extends ULongIsIntegral {
  val self                   = mkNumericOps(this)
  def >>(n: Long): ULong     = (long >>> n).toLong
  def >>>(n: Long)           = >> _
  def <<(n: Long): ULong     = (long << n).toLong
  def +(other: ULong): ULong = self + other
  def -(other: ULong): ULong = self - other
  def unary_- : ULong        = negate(this)
  def *(other: ULong): ULong = self * other
  def /(other: ULong): ULong = self / other
  def toShort: Short         = long.toShort
  def toByte: Byte           = long.toByte
  def toChar: Char           = long.toChar
  def toInt: Int             = long.toInt
  def toLong: Long           = long
  def toBigInt               = (BigInt(long >>> 1) << 1) + (long & 1)
  def toBigDecimal           = BigDecimal(toBigInt)
  override def toString() =
    if (long < 0) toBigInt.toString() else long.toString()

} 
开发者ID:csar,项目名称:Scala-Unsigned,代码行数:30,代码来源:ULong.scala


注:本文中的scala.math.BigDecimal类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。