Browse
Categories

Controlling the Number of Decimals Used in a Text Macro

Reference Number: KB-01897 Last Updated: 06-22-2015 06:50 AM

The information in this article applies to:

Chief Architect Premier or Chief Architect Interiors


QUESTION

I would like to use the RoomVolume text macro in my room labels, but it displays four decimal points. How can I make it display fewer decimal places?


ANSWER

By default, many text macros are setup to simply display the raw, unrounded results of the calculation they perform, but you can easily modify the macro to round down to the nearest value of your choosing.


To use a macro in a room label

  1. In this example, start from a New Plan and draw a 15' by 15' structure.




  2. Select the room and click Open Object  to display the Room Specification dialog.


  3. In the General panel, uncheck Use Room Type and Display in Uppercase, then enter the label of your choice, and the name of the macro you want to use. 

     

    In this case, use the
    RoomVolume macro.


You now know how to apply a macro to a room label so that it displays the volume of the room with the actual output from the calculation. If you change the dimensions of the room to 20' x 20' for example, the results would contain a single decimal place.


     

Next, let's look at controlling the output of the macro.


To round a macro to a specified number of decimal places

  1. From the menu, select CAD> Text> Text Macro Management .


  2. Select the RoomVolume macro and click the Copy button.


  3. Rename the macro to RoomVolumeRounded and modify the code to:

    vol = internal_area * (ceiling_elevation - floor_elevation) / 12
    vol.round(2)




    • To break this down, you are creating an object named vol and setting it equal to the volume of the room.

    • On the next line, you are calling the round function with an argument of 2.
      This tells the program to round the value of vol down to two decimal places.


  4. Click OK then Done.


  5. Select the room again and click Open Object .


  6. Change the macro name to %RoomVolumeRounded% and click OK.


The room label now stops at the nearest hundredth rather than calculating out to the hundred thousand's place.

     


You can apply these concepts to other macros or objects that result in a long string of numbers as the room volume macro tends to do.


MORE INFORMATION

The language Chief Architect uses for its text macros is called Ruby, you can learn more about the different Ruby functions by visiting this online guide: http://ruby-doc.com/docs/ProgrammingRuby/.