Chart DataTable Format Mystery

mikeeve

New Member
Joined
Mar 17, 2012
Messages
42
[SOLVED: workaround found, see bottom]

(Before you reply, I do understand that most decimal numbers can not be expressed exactly in binary format, even simple numbers such as .3. I'm trying to limit the number of digits after the decimal that are shown.)

I'm trying to cleanup the data table in a chart. The data has only 1 or 2 digits after the decimal point, is positive, and less than 100. Typical values are 10.7, 40.1, etc. I've added four 'threshold' horizontal line series to the chart. These are computed double precision values, rounded to 2 decimal digits.

Exhibit A, the Data Table
My problem is that the data values all fit nicely in the data table, but for the computed values, 3 of the 4 display more than the expected 2 digits. Here is what a column from the table looks like:
Data110.6
Data212.4
Computed110.8400002
Computed29.64000003
Computed312.71
Computed412.1700001

<tbody>
</tbody>


When actually printed on the Chart Sheet, three of the values are so squeezed as to be almost unreadable.

Since I had rounded the computed values to 2 digits, I had hoped that they would appear that way in the data table.

Exhibit B, the data series values:
Next, I examined the data series from the Chart Sheet. Here are the arrays for the 4 computed values (values were previously Round()-ed to 2 decimal digits)
(spaces added every 3 digits for readability)

={10.840 000 152 587 8,10.8400001525878,... 10.840 000 152 587 8} appears as 10.840 000 2 in the data table
={ 9.640 000 343 322 75,9.64000034332275,... 9.640 000 343 322 75} appears as 9.640 000 34

={12.710 000 038 146 9,12.7100000381469,... 12.710 000 038 146 9} appears as 12.71
={12.170 000 076 293 9,12.1700000762939,... 12.170 000 076 293 9} appears as 12.1700001

My observation: Looks like Excel is rounding the numbers to 7 digits (even though I previously Rounded to 2!), and then not printing trailing zeros.

Exhibit C, Round() and debug.print
To experiment with interaction between rounding and printing (at least, debug.print), I ran the following in vba editor, immediate window (my input is denoted by >>)

>> a1=10.8400001525878
>> debug.Print a1,round(a1,2)
10.840 000 152 587 8 10.84

>> a1=12.710 000 038 146
>> debug.print a1,round(a1,2)
12.710000038146 12.71

My observation: first value (10.84...) is printed as expected when rounded to 2 digits. Why doesn't the data table appear the same way?

Question: Is this just a quirk of data tables, or is there a way to fix this.

[SOLVED]
(Taking the time to post here always makes me think better!)
I found a solution. I had declared the computed values as Single; I've switched that to Double and now the rounding and printing in the data table works as expected.
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,215,425
Messages
6,124,825
Members
449,190
Latest member
rscraig11

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top