Public Member Functions | List of all members
Format Class Reference

Public Member Functions

 Format (Map specifiers)
 
String format (Number value)
 
Number getResultingValue (Number value)
 
Number getError (Number value)
 
Boolean isSignificant (Number value)
 
Boolean areDifferent (Number a, Number b)
 
Number getMinimumValue ()
 

Detailed Description

Format specification and formatter.

Constructor & Destructor Documentation

◆ Format()

Format ( Map  specifiers)

Constructs the format specification for the given values. See createFormat().

Parameters
specifiersThe format specifiers.

The supported specifiers are:

  1. decimals: Specifies the number of decimals. Defaults to 6.
  2. trim: Specifies that ending zero decimals should be trimming. Defaults to true.
  3. trimLeadZero: Specifies that the leading zero should be excluded. Eg. ".123" instead of "0.123". Defaults to false.
  4. forceSign: Specifies that the '+'-sign must be included for positive numbers. Defaults to false.
  5. forceDecimal: Specifies that the decimal symbol must be included. Defaults to false.
  6. zeropad: Specifies that zeros should be padded to the resulting string to fit the given width. Defaults to false.
  7. width: Specifies the width of the resulting string. Defaults to 0.
  8. separator: Specifies the decimal symbol. Defaults to '.'.
  9. cyclicLimit: Specifies the cyclic limit. Defaults to 0 (disabled).
  10. cyclicSign: Specifies the cyclic sign. Defaults to 0.
  11. scale: Specifies the scale. Defaults to 1.
  12. offset: Specifies the offset. Defaults to 0.
  13. prefix: Specifies the prefix. Defaults to empty string.
  14. suffix: Specifies the suffix. Defaults to empty string.
  15. inherit: Specifies the format to inherit.
var xFormat = createFormat({decimals:3, trim:false, forceSign:true});
xFormat.format(4.5); // returns "+4.500"
var yFormat = createFormat({decimals:3, forceSign:true});
yFormat.format(4.5); // returns "+4.5"
var toolFormat = createFormat({decimals:0, zeropad:true, width:2});
toolFormat.format(7); // returns "07"
var aFormat = createFormat({decimals:3, forceSign:true, forceDecimal:true, scale:DEG});
aFormat.format(Math.Pi); // returns "+180."

Member Function Documentation

◆ areDifferent()

Boolean areDifferent ( Number  a,
Number  b 
)

Returns true if the specified values are different when formatted.

Since
r19569

◆ format()

String format ( Number  value)

Returns the formatted string for the specified value.

◆ getError()

Number getError ( Number  value)

Returns the error for the specified value.

var xFormat = createFormat({decimals:3, trim:false, forceSign:true});
xFormat.format(4.5005); // returns "+4.500"
xFormat.getError(4.5005); // returns -0.0005
xFormat.format(4.4995); // returns "+4.500"
xFormat.getError(4.4995); // returns 0.0005

◆ getMinimumValue()

Number getMinimumValue ( )

Returns the minimum epsilon value.

Returns
1 for no decimals, 0.1 for 1 decimal and so forth.

◆ getResultingValue()

Number getResultingValue ( Number  value)

Returns the resulting value for the specified value.

var xFormat = createFormat({decimals:3, trim:false, forceSign:true});
xFormat.getResultingValue(123.1234); // returns 123.123
xFormat.getResultingValue(123.9876); // returns 123.988

◆ isSignificant()

Boolean isSignificant ( Number  value)

Returns true if the specified value would be non-zero when formatted. See areDifferent() for comparing 2 values.

var xFormat = createFormat({decimals:3, trim:false, forceSign:true});
xFormat.isSignificant(4.5); // returns true
xFormat.isSignificant(0.0005); // returns true - because it is rounded to 0.001
xFormat.isSignificant(0.0004); // returns false
var v = new Vector(-0.00001, 0.0004, -0.001);
xFormat.isSignificant(v.abs.max); // returns true


Generated by Autodesk, Inc. 19 April 2024
Copyright (c) 2012-2024 by Autodesk, Inc.