本文整理汇总了Scala中java.math.BigDecimal类的典型用法代码示例。如果您正苦于以下问题:Scala BigDecimal类的具体用法?Scala BigDecimal怎么用?Scala BigDecimal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BigDecimal类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: ProblemTwentySix
//设置package包名称以及导入依赖的类
package org.nason.euler.twenty
import java.math.{BigDecimal,MathContext,RoundingMode}
import org.nason.euler.EulerUtils
import org.nason.euler.NumberUtils
object ProblemTwentySix {
def main(args: Array[String])
{
println( solution )
}
val One = new BigDecimal(1.0)
val BIGDECIMAL = new MathContext( 2048, RoundingMode.HALF_UP )
def solution =
{
def reciprocal( v:Int ) = One.divide(new BigDecimal(v),BIGDECIMAL)
def bool2int( a:Boolean ) = if (a) 1; else 0
def autocorr( s:String ) =
{
for( d <- 0 until s.length-1 )
yield
( ( 0 until s.length-d )
.map( i => bool2int(s.charAt(i) equals s.charAt(i+d)) )
.reduceLeft(_+_) ) / (s.length-d).toDouble
}
def cycleLength( v:BigDecimal ) =
{
val seq = autocorr( v.toString.substring(2) )
if ( seq.length==0 )
0
else
{
val seq2 = seq.tail
if ( seq2.length==0 )
0
else
( NumberUtils argMax seq2 ) + 1
}
}
( for( d <- 2 until 1000 )
yield "%d: %d".format( d, cycleLength( reciprocal(d) ) ) )
.mkString("\n")
}
}
开发者ID:drkeoni,项目名称:euler-jms-scala,代码行数:51,代码来源:ProblemTwentySix.scala
示例2: StandardArbitraries
//设置package包名称以及导入依赖的类
package movio.cinema.test
import org.scalacheck.Arbitrary
import org.scalacheck.Gen
trait DateTimeArbitrary {
import org.joda.time._
implicit val arbLocalDateTime: Arbitrary[LocalDateTime] =
Arbitrary(Gen.posNum[Long] map (new LocalDateTime(_)))
implicit val arbDateTime: Arbitrary[DateTime] =
Arbitrary(Gen.posNum[Long] map (new DateTime(_)))
}
trait PlayJsonArbitrary {
import java.math.BigDecimal
import play.api.libs.json._
import Arbitrary.arbitrary
import Gen._
implicit val arbJsonObject: Arbitrary[JsObject] = Arbitrary(jsonObjectNode)
implicit val arbJsonArray: Arbitrary[JsArray] = Arbitrary(jsonArrayNode)
lazy val shortText: Gen[String] =
for {
n ? choose(0, 4)
chars ? listOfN(n, alphaNumChar)
} yield chars.mkString
lazy val jsonWholeNumberNode: Gen[JsNumber] = arbitrary[Long] map (n ? JsNumber(new BigDecimal(n)))
lazy val jsonDecimalNumberNode: Gen[JsNumber] = arbitrary[Double] map (n ? JsNumber(new BigDecimal(n)))
lazy val jsonNumberNode: Gen[JsNumber] = oneOf(jsonWholeNumberNode, jsonDecimalNumberNode)
lazy val jsonStringNode: Gen[JsString] = shortText map JsString.apply
lazy val jsonBoolNode: Gen[JsBoolean] = oneOf(true, false) map JsBoolean.apply
lazy val jsonNullNode: Gen[JsNull.type] = const(JsNull)
lazy val jsonValueNode: Gen[JsValue] =
oneOf(jsonNumberNode, jsonStringNode, jsonBoolNode, jsonNullNode, jsonArrayNode, jsonObjectNode)
lazy val jsonArrayNode: Gen[JsArray] =
for {
n ? choose(1, 4)
values ? listOfN(n, jsonValueNode)
} yield JsArray(values)
lazy val jsonObjectNode: Gen[JsObject] =
for {
n ? choose(1, 4)
keys ? listOfN(n, shortText)
values ? listOfN(n, jsonValueNode)
} yield JsObject(keys zip values)
}
object StandardArbitraries extends DateTimeArbitrary with PlayJsonArbitrary
开发者ID:movio,项目名称:generator-apidoc-libs,代码行数:57,代码来源:StandardArbitraries.scala
示例3: MapToJavaPropertiesConversionSpec
//设置package包名称以及导入依赖的类
package com.sky.kafka.utils
import java.math.BigDecimal
import java.util.Properties
import common.BaseSpec
class MapToJavaPropertiesConversionSpec extends BaseSpec {
"mapToProperties" should "convert objects into their string representation" in {
val x = new Properties
MapToJavaPropertiesConversion.mapToProperties(Map[String, Object](
"object" -> new BigDecimal("123.456")
)) shouldBe new Properties {
setProperty("object", "123.456")
}
}
it should "convert classes into the full class name" in {
val x = new Properties
MapToJavaPropertiesConversion.mapToProperties(Map[String, Object](
"class" -> classOf[Exception]
)) shouldBe new Properties {
setProperty("class", "java.lang.Exception")
}
}
}
开发者ID:sky-uk,项目名称:kafka-configurator,代码行数:28,代码来源:MapToJavaPropertiesConversionSpec.scala
示例4: RichBigDecimal
//设置package包名称以及导入依赖的类
package com.gaiam.gcsis.util
import java.math.BigDecimal
import scalaz.{Equal, Monoid}
object RichBigDecimal {
implicit def bigDecimalOrdered(a: BigDecimal) = new Ordered[BigDecimal] {
override def compare(that: BigDecimal): Int = a.compareTo(that)
}
implicit object BigDecimalNumeric extends scala.math.Numeric[BigDecimal] with Ordering[BigDecimal] with Monoid[BigDecimal] with Equal[BigDecimal] {
override def compare(o1: BigDecimal, o2: BigDecimal) = o1.compareTo(o2)
override def plus(x: BigDecimal, y: BigDecimal) = x.add(y)
override def minus(x: BigDecimal, y: BigDecimal) = x.subtract(y)
override def times(x: BigDecimal, y: BigDecimal) = x.multiply(y)
override def negate(x: BigDecimal) = x.negate
override def fromInt(x: Int) = new BigDecimal(x)
override def toInt(x: BigDecimal) = x.intValue
override def toLong(x: BigDecimal) = x.longValue
override def toFloat(x: BigDecimal) = x.floatValue
override def toDouble(x: BigDecimal) = x.doubleValue
override val one = BigDecimal.ONE
override val zero = BigDecimal.ZERO
override def append(x: BigDecimal, y: => BigDecimal) = x.add(y)
override def equal(a: BigDecimal, b: BigDecimal) = a.compareTo(b) == 0
}
}
开发者ID:GaiamTV,项目名称:gcsi-scala-util,代码行数:31,代码来源:RichBigDecimal.scala
示例5: KMScalaKit
//设置package包名称以及导入依赖的类
import java.math.BigDecimal
object KMScalaKit {
def bigDemicalDoubleAdd(number1: Double, number2: Double): Double = {
val a: BigDecimal = new BigDecimal(number1.toString);
val b: BigDecimal = new BigDecimal(number2.toString);
val sum: Double = a.add(b).doubleValue();
return sum;
}
def bigDemicalDoubleAdd(number1: Double, number2: Double, number3: Double): Double = {
val a: BigDecimal = new BigDecimal(number1.toString);
val b: BigDecimal = new BigDecimal(number2.toString);
val c: BigDecimal = new BigDecimal(number3.toString);
val sum: Double = a.add(b).add(c).doubleValue();
return sum;
}
def bigDemicalDoubleSub(number1: Double, number2: Double): Double = {
val a: BigDecimal = new BigDecimal(number1.toString);
val b: BigDecimal = new BigDecimal(number2.toString);
val res: Double = a.subtract(b).doubleValue();
return res;
}
def bigDemicalDoubleMul(number1: Double, number2: Double): Double = {
val a: BigDecimal = new BigDecimal(number1.toString);
val b: BigDecimal = new BigDecimal(number2.toString);
val res: Double = a.multiply(b).doubleValue();
return res;
}
def bigDemicalDoubleMul(number1: Double, number2: Double, number3: Double): Double = {
val a: BigDecimal = new BigDecimal(number1.toString);
val b: BigDecimal = new BigDecimal(number2.toString);
val c: BigDecimal = new BigDecimal(number2.toString);
val res: Double = a.multiply(b).multiply(c).doubleValue();
return res;
}
def bigDemicalDoubleDiv(number1: Double, number2: Double): Double = {
val a: BigDecimal = new BigDecimal(number1.toString);
val b: BigDecimal = new BigDecimal(number2.toString);
val res: Double = a.divide(b).doubleValue();
return res;
}
}
开发者ID:kimihe,项目名称:Swallow,代码行数:55,代码来源:KMScalaKit.scala
注:本文中的java.math.BigDecimal类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论