四舍五入为10的幂 [英] Rounding to a power of 10

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

问题描述

我有一个变量tauMax,我想将向上舍入到最接近的10的幂(1,10,100,1000 ...).我正在使用以下表达式在tau数组中找到最接近最大值的整数.我正在寻找最大值,因为我正在尝试计算10的幂,这应该是x轴的截止值.因此,tauMax等于756,所以我想有一个输出1000或3(对于10 ^ 3)的表达式.

I have a variable, tauMax, that I want to round up to the nearest power of ten(1, 10, 100, 1000...). I am using the below expression to find the closest integer to the max value in the tau array. I am finding the max value because I am trying to calculate the power of ten that should be the x axis cutoff. In this cause, tauMax is equal to 756, so I want to have an expression that outputs either 1000, or 3(for 10^3).

tauMax = round(max(tau));

非常感谢您的帮助!

推荐答案

由于您使用的是以10为底的数字,因此只需使用log10即可获取位数.

Since you're talking base 10, you could just use log10 to get the number of digits.

怎么样:

>> ceil(log10(756))

ans =

     3

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

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