top of page

51. Format a Number as "nine point seven five"

Description

Formats a number or percentage with a decimal in the form "nine point seven five [per cent]".

Code

SET NumVar TO ROUND( NumVar, 2 )
SET Temp-n TO POSITION( "«NumVar»", "." )

// Has fractional portion
IF Temp-n > 0

// Integer portion
FORMAT(
INTEGER( FIRST( "«NumVar»", Temp-n - 1 )) ,
"zero"
) + " point "

// Tenths portion
RESULT + FORMAT(
INTEGER( MID( "«NumVar»", Temp-n + 1, 1 )) ,
"zero"
)

// Hundredths portion
IF NumVar != TRUNCATE( NumVar, 1 )
RESULT + " " +
FORMAT(
INTEGER( LAST( "«NumVar»", 1 )) ,
"zero"
)
END IF

// Has no fractional portion
ELSE
FORMAT( NumVar , "zero" )
END IF

// Optional: for percentages
// RESULT + " per cent"

Explanation

The HotDocs format "nine point nine" formats a number with two decimal places as "nine point seventy five." This premium computation, on the other hand, formats the same number as "nine point seven five." It is especially useful for percentages: "nine point seven five per cent." It will format up to two decimal places: 9.75. Additional decimal places are rounded.

The computation relies on two variables: NumberVar, which is the number variable or percentage being formatted, and Temp-n, a temporary number variable (when you create it be sure to set these Advanced Options: Ask Only in Dialog, Don't warn if unanswered, Don't save in answer file). It formats up to two decimal places: 9.75. Additional decimal places are rounded.

See also, 52: Format a Fraction as "four and one half", 62: "All (100%)", #0116: (Even) Smarter Fraction Formatting, #0150: Decimal Formatter.

©2023 by My Site. Proudly created with Wix.com

  • Facebook
  • Twitter
  • LinkedIn
bottom of page