當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript js-quantities.toFloat函數代碼示例

本文整理匯總了TypeScript中js-quantities.toFloat函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript toFloat函數的具體用法?TypeScript toFloat怎麽用?TypeScript toFloat使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了toFloat函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

 it("should create unitless", () => {
   var qty = Qty("1");
   expect(qty.toFloat()).toBe(1);
   expect(qty.numerator).toEqual(["<1>"]);
   expect(qty.denominator).toEqual(["<1>"]);
   qty = Qty("1.5");
   expect(qty.toFloat()).toBe(1.5);
   expect(qty.numerator).toEqual(["<1>"]);
   expect(qty.denominator).toEqual(["<1>"]);
 });
開發者ID:Kroisse,項目名稱:DefinitelyTyped,代碼行數:10,代碼來源:js-quantities-tests.ts

示例2: it

 it("should create unitless from numbers", () => {
   const qty = Qty(1.5);
   expect(qty.toFloat()).toBe(1.5);
   expect(qty.numerator).toEqual(["<1>"]);
   expect(qty.denominator).toEqual(["<1>"]);
 });
開發者ID:Mikhus,項目名稱:DefinitelyTyped,代碼行數:6,代碼來源:js-quantities-tests.ts

示例3: Qty

Qty.getAliases('m'); // => [ 'm', 'meter', 'meters', 'metre', 'metres' ]

const qty1 = Qty('1m');
const qty2 = Qty('2m');

qty1.isCompatible(qty2); // => true or false

qty.kind(); // => 'length', 'area', etc...

qty.isUnitless(); // => true or false
qty.isBase(); // => true if quantity is represented with base units

qty.toBase(); // converts to SI units (10 cm => 0.1 m) (new instance)

qty.toFloat(); // returns scalar of unitless quantity (otherwise throws error)

qty.to('m'); // converts quantity to meter if compatible or throws an error (new instance)
qty1.to(qty2); // converts quantity to same unit of qty2 if compatible or throws an error (new instance)

qty.inverse(); // converts quantity to its inverse ('100 m/s' => '.01 s/m')
// Inverses can be used, but there is no special checking to
// rename the units
Qty('10ohm').inverse(); // '.1/ohm' (not '.1S', although they are equivalent)
// however, the 'to' command will convert between inverses also
Qty('10ohm').to('S'); // '.1S'

var convert = Qty.swiftConverter('m/h', 'ft/s'); // Configures converter

// Converting single value
var converted = convert(2500); // => 2.278..
開發者ID:Kroisse,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:js-quantities-tests.ts

示例4: it

 it("should create unitless from numbers", function () {
   var qty = Qty(1.5);
   expect(qty.toFloat()).toBe(1.5);
   expect(qty.numerator).toEqual(["<1>"]);
   expect(qty.denominator).toEqual(["<1>"]);
 });
開發者ID:ArtemZag,項目名稱:DefinitelyTyped,代碼行數:6,代碼來源:js-quantities-tests.ts


注:本文中的js-quantities.toFloat函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。