本文整理汇总了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))
}
}
示例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)
}
}
示例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"), ""))
}
示例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)
}
}
}
示例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()
}