Browse
Categories

Controlling the Number of Decimals Used in a Text Macro

Reference Number: KB-01897 Last Updated: 11-11-2014 12:28 PM

The information in this article applies to:

Chief Architect Premier or Chief Architect Interiors or Chief Architect Lite


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 we will start from a New Plan and draw a 15ft. by 15ft. structure.




  2. Select the room and click Open Object .


  3. Under the General panel, uncheck User Room Type and Display in Uppercase.


  4. Enter the label of your choice and the name of the macro you want to use. In this case we are using the RoomVolume macro.




You now know how to apply a macro to a room label so that it works, displaying the volume of the room. And as you can see, the results are pretty long. This is simply the actual output from the calculation. If we were to change the dimensions of our room to 20'x20' for example, the results would simply contain a single decimal place.



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


Rounding 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 we are creating an object named vol and setting it equal to the volume of the room.

    • On the next line we 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. Then select our room again and click Open Object .


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


Our 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 it's 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/.