【发布时间】:2011-11-18 12:34:18
【问题描述】:
如何按给定因子计算纵横比(格式为integer:integer)?
例如,纵横比 16:9 的系数为 1.778,因为 16 / 9 = 1.778。但是我怎样才能找到这个因素的比率呢?所以
Dimension getAspectRatio(double factor) {
...
}
public static void main(String[] arguments) {
Dimension d = getAspectRatio(16d / 9d);
System.out.println(d.width + ":" + d.height);
}
应该返回
16:9
【问题讨论】:
-
在您的输入中找到best rational approximation 可能会为您提供很好的服务
标签: java math aspect-ratio