• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala NumberFormat类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: JVMUtil

//设置package包名称以及导入依赖的类
package org.argus.jawa.core.util

import java.io.{BufferedReader, InputStreamReader}
import java.net.URLClassLoader
import java.text.NumberFormat

 
object JVMUtil {
	def startSecondJVM[C](clazz: Class[C], jvmArgs: List[String], args: List[String], redirectStream: Boolean): Int = {
    val separator = System.getProperty("file.separator")
    val classpath = Thread.currentThread().getContextClassLoader.asInstanceOf[URLClassLoader].getURLs.map(_.getPath()).reduce((c1, c2) => c1 + java.io.File.pathSeparator + c2)
    val path = System.getProperty("java.home") + separator + "bin" + separator + "java"
    val commands: IList[String] = List(path) ::: jvmArgs ::: List("-cp", classpath, clazz.getCanonicalName.stripSuffix("$")) ::: args
    import scala.collection.JavaConverters._
    val processBuilder = new ProcessBuilder(commands.asJava)
    processBuilder.redirectErrorStream(redirectStream)
    val process = processBuilder.start()
    val is = process.getInputStream
    val isr = new InputStreamReader(is)
    val br = new BufferedReader(isr)
    var line = br.readLine()
    while (line != null) {
      println(line)
      line = br.readLine()
    }
    process.waitFor()
  }
  
  def showMemoryUsage(): Unit = {
    val runtime = Runtime.getRuntime
    val format = NumberFormat.getInstance()
    
    val sb = new StringBuilder()
    val maxMemory = runtime.maxMemory()
    val allocatedMemory = runtime.totalMemory()
    val freeMemory = runtime.freeMemory()
    
    sb.append("free memory: " + format.format(freeMemory / 1024 / 1024) + " ")
    sb.append("allocated memory: " + format.format(allocatedMemory / 1024 / 1024) + " ")
    sb.append("max memory: " + format.format(maxMemory / 1024 / 1024) + " ")
    sb.append("total free memory: " + format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024 / 1024) + " ")
    println(sb.toString())
  }
} 
开发者ID:arguslab,项目名称:Argus-SAF,代码行数:45,代码来源:JVMUtil.scala


示例2: DefaultStdI18N

//设置package包名称以及导入依赖的类
package s_mach.i18n.impl

import java.text.NumberFormat

import s_mach.i18n._
import s_mach.i18n.messages.MessageLiteral

class DefaultStdI18N extends StdI18N {

  // Note: NumberFormat is not thread-safe so can't save instance
  // without synchronization

  val m_true = MessageLiteral('m_true)
  val m_false = MessageLiteral('m_false)

  def i18n(value: Boolean)(implicit cfg: I18NConfig) = {
    if(value) {
      m_true()
    } else {
      m_false()
    }
  }
  def i18n(value: Byte)(implicit cfg: I18NConfig) = {
    val fmt = NumberFormat.getIntegerInstance(cfg.locale)
    I18NString(fmt.format(value.toLong))
  }
  def i18n(value: Short)(implicit cfg: I18NConfig) = {
    val fmt = NumberFormat.getIntegerInstance(cfg.locale)
    I18NString(fmt.format(value.toLong))
  }
  def i18n(value: Int)(implicit cfg: I18NConfig) = {
    val fmt = NumberFormat.getIntegerInstance(cfg.locale)
    I18NString(fmt.format(value.toLong))
  }
  def i18n(value: Long)(implicit cfg: I18NConfig) = {
    val fmt = NumberFormat.getIntegerInstance(cfg.locale)
    I18NString(fmt.format(value))
  }
  def i18n(value: Float)(implicit cfg: I18NConfig) = {
    val fmt = NumberFormat.getNumberInstance(cfg.locale)
    I18NString(fmt.format(value.toDouble))
  }
  def i18n(value: Double)(implicit cfg: I18NConfig) = {
    val fmt = NumberFormat.getNumberInstance(cfg.locale)
    I18NString(fmt.format(value))
  }
  def i18n(value: BigInt)(implicit cfg: I18NConfig) = {
    val fmt = NumberFormat.getNumberInstance(cfg.locale)
    I18NString(fmt.format(value.underlying()))
  }
  def i18n(value: BigDecimal)(implicit cfg: I18NConfig) = {
    val fmt = NumberFormat.getNumberInstance(cfg.locale)
    I18NString(fmt.format(value.underlying()))
  }

  override def toString = "DefaultStdI18N"
} 
开发者ID:S-Mach,项目名称:s_mach.i18n,代码行数:58,代码来源:DefaultStdI18N.scala


示例3: Currency

//设置package包名称以及导入依赖的类
package controllers

import java.text.NumberFormat
import java.util.Locale

import scala.collection.immutable

case class Currency private (name: String, step: Int, locale: Locale) {
  
  private val currency = java.util.Currency.getInstance(name)
  private val format = NumberFormat.getCurrencyInstance(locale)
  
  def format(value: Int): String = format.format(toDecimal(value))

  def getDisplayName: String = currency.getDisplayName

  private def toDecimal(value: Int): Double = if (currency.getDefaultFractionDigits > 0) {
    value.toDouble / Math.pow(10, currency.getDefaultFractionDigits)
  } else {
    value
  }

  def formatDecimal(value: Int): String = if (currency.getDefaultFractionDigits > 0) {
    String.format("%." + currency.getDefaultFractionDigits + "f", java.lang.Double.valueOf(toDecimal(value)))
  } else {
    Integer.toString(value)
  }

  def getDecimalStep: Double = toDecimal(step)

  def toPriceUnits(value: Double): Int = if (currency.getDefaultFractionDigits > 0) {
    (value * Math.pow(10, currency.getDefaultFractionDigits)).round.toInt
  } else {
    value.round.toInt
  }

  def isValidStep(value: Double): Boolean = {
    val price = toPriceUnits(value)
    price % step == 0
  }
}

object Currency {
  val USD = Currency("USD", 50, Locale.US)
  val EUR = Currency("EUR", 50, Locale.GERMANY)
  val GBP = Currency("GBP", 50, Locale.UK)
  val JPY = Currency("JPY", 50, Locale.JAPAN)
  val CNY = Currency("CNY", 100, Locale.CHINA)
  val CAD = Currency("CAD", 50, Locale.CANADA)
  val AUD = Currency("AUD", 50, Locale.forLanguageTag("en-AU"))

  val values = immutable.Seq(
    USD, EUR, GBP, JPY, CNY, CAD, AUD
  )

  private val map = values.map(c => c.name -> c).toMap

  def isDefined(name: String): Boolean = map.contains(name)
  def valueOf(name: String): Currency = map(name)
} 
开发者ID:lagom,项目名称:online-auction-scala,代码行数:61,代码来源:Currency.scala


示例4: formatDate

//设置package包名称以及导入依赖的类
package com.speech.grammarmatch

import java.text.NumberFormat
import java.time.format.DateTimeFormatter
import java.util.Locale


  def formatDate( inDate: String ) : String = {
    val dateFormat = DateTimeFormatter.ofPattern("yyyyMMdd")
    val outFormat = DateTimeFormatter.ofPattern("MMM dd yyyy")
    outFormat.format( dateFormat.parse( inDate ))
  }

  def formatTime( time: String ) : String = {
    val inTime = time.toUpperCase
    val timeFormat = DateTimeFormatter.ofPattern("hhmma")
    val outFormat = DateTimeFormatter.ofPattern("h:mma")
    outFormat.format( timeFormat.parse(inTime) )
  }

  def formatCurrency( currency:String ) : String = {
    val currencyFormatter = NumberFormat.getCurrencyInstance( Locale.US )
    currencyFormatter.format( currency.toDouble )
  }



  def grammarFormatter( grammarType:GrammarType, sentence:String ) = grammarType match {
    case GrammarType.CURRENCY => formatCurrency( sentence )
    case GrammarType.DATE => formatDate( sentence )
    case GrammarType.NUMBER => sentence
    case GrammarType.ORDINAL => sentence
    case GrammarType.TIME => formatTime( sentence )
  }


  def grammarMaxMin( grammarType:GrammarType ) = grammarType match {
    //returns (MAX,MIN) word counts for the different grammars
    case GrammarType.CURRENCY => ( 15,2 )
    case GrammarType.DATE => ( 8,2 )
    case GrammarType.NUMBER => ( 9,1 )
    case GrammarType.ORDINAL => ( 9,1 )
    case GrammarType.TIME => ( 4,2 )
  }

} 
开发者ID:strohs,项目名称:play-grammars,代码行数:47,代码来源:GrammarUtils.scala


示例5: Formatters

//设置package包名称以及导入依赖的类
package br.com.caelum.argentum

import java.text.NumberFormat
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter



object Formatters {

	implicit def toRichBigDecimal(value:BigDecimal) = new RichBigDecimal(value)
	implicit def toRichLocalDateTime(value:LocalDateTime) = new RichLocalDateTime(value)
}

class RichBigDecimal(val value:BigDecimal){
	def toCurrencyFormat = NumberFormat.getCurrencyInstance.format(value)
}

class RichLocalDateTime(val value:LocalDateTime){
	def formatTo = {
		val dateTimeFormat = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")
		value.format(dateTimeFormat)
	}

	def formatTo(pattern:String) = {
		val dateTimeFormat = DateTimeFormatter.ofPattern(pattern)
		value.format(dateTimeFormat)
	}
} 
开发者ID:DaniloAndrade,项目名称:Argentum,代码行数:30,代码来源:Formatters.scala


示例6: formatter

//设置package包名称以及导入依赖的类
package lila.app
package templating

import java.text.NumberFormat
import java.util.Locale
import scala.collection.mutable.AnyRefMap

import lila.user.UserContext

trait NumberHelper { self: I18nHelper =>

  private val formatters = AnyRefMap.empty[String, NumberFormat]

  private def formatter(implicit ctx: UserContext): NumberFormat =
    formatters.getOrElseUpdate(
      lang(ctx).language,
      NumberFormat getInstance new Locale(lang(ctx).language)
    )

  def showMillis(millis: Int)(implicit ctx: UserContext) = formatter format ((millis / 100).toDouble / 10)

  implicit def richInt(number: Int) = new {
    def localize(implicit ctx: UserContext): String = formatter format number
  }

  def nth(number: Int) = if ((11 to 13).contains(number % 100))
    "th"
  else number % 10 match {
    case 1 => "st"
    case 2 => "nd"
    case 3 => "rd"
    case _ => "th"
  }
} 
开发者ID:DrNixx,项目名称:line,代码行数:35,代码来源:NumberHelper.scala


示例7: Count

//设置package包名称以及导入依赖的类
package org.broadinstitute.hail.driver

import java.text.NumberFormat
import java.util.Locale

import org.broadinstitute.hail.Utils._
import org.kohsuke.args4j.{Option => Args4jOption}

object Count extends Command {

  class Options extends BaseOptions {
    @Args4jOption(name = "-g", aliases = Array("--genotypes"),
      usage = "Calculate genotype call rate")
    var genotypes: Boolean = false
  }

  def newOptions = new Options

  def name = "count"

  def description = "Print number of samples, variants, and called genotypes in current dataset"

  def supportsMultiallelic = true

  def requiresVDS = true

  def run(state: State, options: Options): State = {
    val vds = state.vds

    val (nVariants, nCalledOption) = if (options.genotypes) {
      val (nVar, nCalled) = vds.rdd.map { case (v, (va, gs)) =>
        (1L, gs.count(_.isCalled).toLong)
      }.fold((0L, 0L)) { (comb, x) =>
        (comb._1 + x._1, comb._2 + x._2)
      }
      (nVar, Some(nCalled))
    } else (vds.rdd.count(), None)

    val sb = new StringBuilder()

    val formatter = NumberFormat.getNumberInstance(Locale.US)
    def format(a: Any) = "%15s".format(formatter.format(a))


    sb.append("count:\n")
    sb.append(s"  nSamples   ${format(vds.nSamples)}\n")
    sb.append(s"  nVariants  ${format(nVariants)}")

    nCalledOption.foreach { nCalled =>
      val nGenotypes = nVariants * vds.nSamples
      val callRate = divOption(nCalled, nGenotypes)
      sb += '\n'
      sb.append(s"  nCalled    ${format(nCalled)}\n")
      sb.append(s"  callRate   ${"%15s".format(callRate.map(r => (r * 100).formatted("%.3f%%")).getOrElse("NA"))}")
    }

    info(sb.result())
    state
  }
} 
开发者ID:Sun-shan,项目名称:Hail_V2,代码行数:61,代码来源:Count.scala


示例8: richString

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

import org.joda.time.format.DateTimeFormat
import java.util.Locale
import java.text.{NumberFormat, DecimalFormat}

package object ingparser {
  implicit def richString(input: String) = new {
    def asDateTime = DateTimeFormat.forPattern("dd MMMMM yyyy").withLocale(new Locale("RO")).parseDateTime(input)

    def asDecimal = {
      val format: DecimalFormat = NumberFormat.getInstance(new Locale("RO")).asInstanceOf[DecimalFormat]
      format.setParseBigDecimal(true)
      BigDecimal.apply(format.parse(input).asInstanceOf[java.math.BigDecimal])
    }
  }

} 
开发者ID:dvulpe,项目名称:homebankcsv_parser,代码行数:19,代码来源:package.scala


示例9: LabyrinthBench

//设置package包名称以及导入依赖的类
import scala.util.Try
import java.text.NumberFormat

import labyrinth._

object LabyrinthBench extends App {
  def time(iter: Int)(block: => Unit): Unit = {
      val t0 = System.nanoTime()
      for(_ <- 0 until iter) {
        val result = block
      }
      val ns = NumberFormat.getIntegerInstance().format((System.nanoTime() - t0) / iter)
      println(s"Elapsed time: $ns ns/iter")
  }

  val iterOpt = args.headOption match { case Some(arg) => Try(arg.toInt).toOption case _ => None }
  val iter = iterOpt match { case Some(iter) => iter case _ => 1000 }

  {
    val wall = Wall(10, 10)
    println(s"Iterating: $iter 10x10")
    time(iter) {
      wall.closeAll.carve
      wall.toString
    }
  }

  {
    val wall = Wall(20, 20)
    println(s"Iterating: $iter 20x20")
    time(iter) {
      wall.closeAll.carve
      wall.toString
    }
  }

  {
    val wall = Wall(50, 50)
    println(s"Iterating: $iter 50x50")
    time(iter) {
      wall.closeAll.carve
      wall.toString
    }
  }

  {
    val wall = Wall(100, 100)
    println(s"Iterating: $iter 100x100")
    time(iter) {
      wall.closeAll.carve
      wall.toString
    }
  }
} 
开发者ID:royaltm,项目名称:scala-labyrinth,代码行数:55,代码来源:LabyrinthBench.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala DataType类代码示例发布时间:2022-05-23
下一篇:
Scala verify类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap