The HotDocs Computation Archive
Get Extra Help

0051 - 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, #0052: Format a Fraction as "four and one half", #0062: "All (100%)", #0116: (Even) Smarter Fraction Formatting, #0150: Decimal Formatter.

 

• Model Template •

This template has everything you need set up and configured for you. It will work as-is, or can be adapted to your variable and dialog names. It contains: 1) sample Word and WordPerfect templates (or an Automator form) to demonstrate an implementation of the computation, 2) a component file containing the computation and all supporting dialogs and variables, and 3) instructions for adapting the computation for your use.

(Go to the download page)

 
 

• Contributors •

LegalCS