`
hideto
  • 浏览: 2650041 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ASCB阅读笔记四、Numbers and Math

阅读更多
显示最近的整数(四舍五入)
Math.round(204.499)  // 204
Math.round(401.5)    // 402

指定向上或向下
Math.floor(204.99)   // 204
Math.ceil(401.01)    // 402

控制精确度
Math.round(90.337 / .01) * .01  // 90.34
Math.round(92.5 / 5) * 5        // 95
Math.round(92.5 / 10) * 10      // 90

由此可以写一个Util类
NumberUtil.round(Math.PI)         // 3
NumberUtil.round(Math.PI, .01)    // 3.14
NumberUtil.round(Math.PI, .0001)  // 3.1416
NumberUtil.round(123.456, 1)      // 123
NumberUtil.round(123.456, 6)      // 126
NumberUtil.round(123.456, .01)    // 123.46

NumberFormat也是ASCB的一个Util类
var styler:NumberFormat = new NumberFormat("#,###,###,###.00");
Locale.slanguage = "fr";
trace(styler.format(1234));                                         // 1.234,00
trace(styler.format(12345, {group: ",", decimal: "."}));            // 12,345.00
trace(styler.format(123456));                                       // 123.345,00
Locale.slanguage = "en";
trace(styler.format(1234567));                                      // 1,234,567.00
trace(styler.format(12345678, new Locale("es", "ES")));             // 12.345.678,00
trace(styler.format(123456789, {group: "|", decimal: ","}));        // 123|456|789,00

Currency Amounts Formatting
var styler:NumberFormat = new NumberFormat();
trace(styler.currencyFormat(123456));                                  // $123,456.00
Locale.slanguage = "nl";
trace(styler.currencyFormat(123456));                                  // 123.456,00
trace(styler.currencyFormat(123456, new Locale("sv")));                // 123,456.00kr
trace(styler.currencyFormat(123456, {group: ",", decimal: ".",
                                     currency: "@", before: false}));  // 123,456.00@

生成随机数
// Generate a random integer from 0 to 100.
trace(NumberUtilities.random(0, 100));

// Generate a random multiple of 5 from 0 to 100.
trace(NumberUtilities.random(0, 100, 5));

// Generate a random number from -10 to 10, rounded to the
// nearest tenth.
trace(NumberUtilities.random(-10, 10, .1));

// Generate a random number from -1 to 1, rounded to the
// nearest five-hundredth.
trace(NumberUtilities.random(-1, 1, .05));

掷硬币
var randomNumber:Number = NumberUtilities.random(0, 1);
var text = (randomNumber == 0) ? "heads" : "tails";

掷骰子
var die1:uint = NumberUtilities.random(1, 6);
var die2:uint = NumberUtilities.random(1, 6);
var dice:uint = die1 + die2;

玩纸牌
// Deal four hands.
var hands:Array = cards.deal(4);

生成唯一数
// Display a unique number.
trace(NumberUtilities.getUnique());

角度转换
var converterToRadians:Converter = Unit.DEGREE.getConverterTo(Unit.RADIAN);
var converterToDegrees:Converter = Unit.RADIAN.getConverterTo(Unit.DEGREE);
trace(converterToRadians.convertWithLabel(1));
trace(converterToRadians.convertWithLabel(57.2957795130823));
trace(converterToDegrees.convertWithLabel(1));
trace(converterToDegrees.convertWithLabel(0.0174532925199433));

/*
   Displays:
   0.0174532925199433 radians
   1 radian
   57.2957795130823 degrees
   1 degree
*/

计算两点之间的距离
var c:Number = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));

计算圆上的点
x1 = x0 + (Math.cos(angle) * radius);
y1 = y0 + (Math.sin(angle) * radius);

量度转换
// Display the categories that are supported.
trace(Unit.getCategories(  ));

// Display the units supported in the temperature category.
trace(Unit.getUnits("temperature"));

var converter:Converter = Unit.CELCIUS.getConverterTo(Unit.FAHRENHEIT);
trace(converter.convert(0));  // Displays: 32
分享到:
评论

相关推荐

    ActionScript ascb包

    ascb包,直接解压放在src目录下。其中具体用法,还是得找些文档

    FLEX的ASCB函数包

    通过ASCB包,可以在FLEX环境中对字符、数字、日期等进行各种快捷的函数处理。如字符转为日期等。

    ascb hardware card

    This manual describes the Goebel NIC, a test resource for exercising ASCB-D interface bus on Honeywell EPIC programs. This is a new generation of test equipment designed specifically for simulation.

    ascb.drawing.Pen 类

    但是大多数的图形用Graphics API还是很难画出的,AS3CBLibrary (http://www.rightactionscript.com/ascb) 提供了一个 ascb.drawing.Pen 类。Pen 类是Graphics 类的代理(包装)类。你可以构造一个新的Pen 实例然后...

    ascb.drawing.pen

    但是大多数的图形用Graphics API还是很难画出的,AS3CBLibrary (http://www.rightactionscript.com/ascb) 提供了一个 ascb.drawing.Pen 类。Pen 类是Graphics 类的代理(包装)类。你可以构造一个新的Pen 实例然后...

    安科瑞ASCB1系列智能微型断路器样本

    安科瑞ASCB1系列智能微型断路器样本,

    591 ASCB1系列智能微型断路器安装使用说明书V1.00-20220715

    安科瑞ASCB1系列智能微型断路器产品使用,安装说明书

    AS3CBLibrary

    AS3CBLibrary资源包,ascb包,各种as类

    flash actionscript3 as3游戏开发教程合集(2本经典合一)+AS3CBLibrary_ascb包.zip

    flash actionscript3 as3游戏开发教程合集(2本经典合一)+AS3CBLibrary_ascb包.zip

    flash as3.0游戏

    一款带有代码的flash小游戏,直接下载,马上可以打开,不用解压缩.

    ASP封装成DLL

    本文档告诉读者怎样将ASP封装成DLL,需要使用word2007打开文档。

    鲜花网站建设

    if iFileNameStart>0 and iFileNameStart iFileNameEnd=inString(iFileNameStart+10,"""") mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10) iStart=inString(iFileNameEnd+1,...

    用VBS获取网页源代码.vbs

    ThisCharCode = AscB(MidB(vIn,i,1)) If ThisCharCode ; Then strReturn = strReturn & Chr(ThisCharCode) Else NextCharCode = AscB(MidB(vIn,i+1,1)) strReturn = strReturn & Chr(CLng(ThisCharCode) * &...

    无组件ASP文件上传源代码

    if iFileNameStart>0 and iFileNameStart iFileNameEnd=inString(iFileNameStart+10,"""") mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10) iStart=inString(iFileNameEnd+1,vbEnter&...

    全国所有银行简称.xlsx

    ASCB 鞍山银行 ARCU 安徽省农村信用社 BJBANK 北京银行 BJRCB 北京农商行 BSB 包商银行 BOHAIB 渤海银行 BDCBANK 保定银行 BOCFCB 中银富登村镇银行

    html读出文本文件内容

    [removed] Function bytes2BSTR(vIn) strReturn = “” For i = 1 To LenB(vIn) ThisCharCode = AscB(MidB(vIn,i,1)) If ThisCharCode < &H80 Then strReturn = strReturn & Chr(ThisCharCode)...

    java script或者vbscript 脚本使用原始socket通信

    s = s & chr(ascb(midb(binary, i, 1))) next binarytostring= s end function function rsbinarytostring(xbinary) dim binary if vartype(xbinary)=8 then binary = multibytetobinary(xbinary) ...

    一段采集程序代码

    @LANGUAGE=”JScript” CODEPAGE=”936″%> [removed] Function bytes2BSTR(vIn) strReturn = “” For i = 1 To LenB(vIn) ThisCharCode = AscB(MidB(vIn,i,1)) If ThisCharCode < &H80 Then ...

    百度小偷

    Function bytes2BSTR(vIn)strReturn = “”For i = 1 To LenB(vIn)ThisCharCode = AscB(MidB(vIn,i,1))If ThisCharCode < &H80 ThenstrReturn = strReturn & Chr(ThisCharCode)ElseNextCharCode = AscB(MidB(vIn,...

Global site tag (gtag.js) - Google Analytics