Skip to main content
4-Participant
October 29, 2025
Solved

Rounding all elements of an array

  • October 29, 2025
  • 2 replies
  • 914 views

I'm using WRITECSV to write the contents of a matrix to a .CSV file. The WRITECSV function writes the contents with full precision, giving me numbers with 18 decimal places. I want to round the elements to a few decimal places. I wrote a function to do this, but it feels kind of clunky. Is there a native way to accomplish what I'm trying to do? I'm using Prime 11.

MJ_10071773_0-1761769850720.png

 

Best answer by StuartBruff

2025 10 29 A.png

 

Stuart

2 replies

4-Participant
October 29, 2025

Oops, I realized that I redefined the native function "round". Not good. But my basic question remains.

23-Emerald V
October 29, 2025

@MJ_10071773 wrote:

Oops, I realized that I redefined the native function "round". Not good. But my basic question remains.


 

I wouldn't worry unduly about redefining the native function.  I do it almost all the time when I want the native function to do something different.

 

By default, Mathcad will assign the "Variable" Label to your redefined function.  The original function is still available with different labels.

 

To see or change a name's label, click on the name, then look in either the Math tab for Labels or in the Math Formatting tab (as seen in the image below).

 

The tab should indicate the name's label.  The formatting tab lets you change a label's formatting to display it in a different colour or with a different attribute (bold, italic).  Unfortunately, you can't change a label's font or font size independently of the other labels.

 

I usually choose bold, green for the Function label, but I've changed it to red to make it stand out a bit better (hopefully).

 

You should be able to see in my previous post how it allows you to distinguish between the built-in round and both our redefined rounds.

 

2025 10 29 C.png

 

Stuart

4-Participant
October 29, 2025

Thank you! I learned more about Mathcad than I thought I would with this question.

23-Emerald V
October 29, 2025
4-Participant
October 30, 2025

Unfortunately, the element-wise rounding didn't accomplish my end goal. I wanted it to round the mantissa when working with numbers in scientific notation. Do you see an elegant way to accomplish that?

MJ_10071773_0-1761853480035.png

 

4-Participant
October 30, 2025

Here was Chatgpt's solution to my question

MJ_10071773_0-1761854216217.png

I couldn't figure out how to incorporate the vectorization (element-wise) operator into the function definition.