饼图四舍五入到100% [英] Rounding to 100% for pie chart

查看:342
本文介绍了饼图四舍五入到100%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要对3个随机存在的整数求和,然后将每个数字除以总和得出百分比.

I am taking the sum 3 random existing whole numbers and then dividing each individual number by the sum to get the percentage.

保证我始终获得100%的最佳方法是什么?是否有任何vb.net函数可以帮助我解决此问题,或者我基本上必须手动找到3个百分比的总和与100%的总和之间的差,将其相除,然后将其加到3个百分比中.

What is the best way to guarantee I will always get 100%? Is there any vb.net function that will help me with this or do I basically have to manually find the difference between the sum of my 3 percentages and 100%, divide it, and add it to my 3 percentages.

推荐答案

您计算百分比,将除最后一个以外的所有百分比相加,然后从100中减去.如果您尝试分发错误,它将无济于事.像第一次计算一样四舍五入.

You calculate the percentages, add all but the last together and subtract from 100. If you ry to distribute the error, it won't help since it would get rounded off like in the first calculation.

有时候最好将错误加到最大的数字上,这样不会有太大的问题

Sometimes it might be best to add the error to the largest number so it won't be that much off

这篇关于饼图四舍五入到100%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆