如何在Delphi中将浮点值显示为科学参数
我们经常需要以带有乘数和单位的科学形式显示浮点值,例如 1500 V(伏特)的值将显示为 1.5 kV。 1e-4 V 的非常小的电压将显示为 100 uV。多年来,我们一直使用内部创建的例程来进行浮点到字符串的转换,但我最近想知道这种方法是否更普遍可用?
We have a frequent need to display floating point values in a scientific form with multiplier and units, for example the value of 1500 V (volts) would be displayed as 1.5 kV.
A very small voltage of 1e-4 V would be displayed as 100 uV. For years we've used an internally created routine to make this float to string conversion but I was minded to wonder recently whether such a means was more generally available?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我正在使用这个 FormathWithPrefix 函数,但对对数知之甚少...:)
支持 SI 前缀 范围!
I'm using this FormathWithPrefix function with little knowledge about logarithms... :)
Support SI prefixes range!
如果您的目标是使您的例程更加“原生”,您可以查看 ConvUtils 和 StdConvs 单元,看看是否可以将您的例程基于这些单元提供的转换函数。 (不确定这些单元是什么时候引入的。快速谷歌搜索建议使用 Delphi 6)
但这不一定会给您带来多大帮助。 (取决于您想要实现的目标)
If your goal is to make your routines more "native", you could take a look at the ConvUtils and StdConvs units and see if you could base your routines on the conversion functions offered by these units. (Not sure when those units were introduced. Quick google search suggest Delphi 6)
But that won't necessarily achieve much for you. (Depending on what you are looking to achieve)
在这里试试:http://www.delphibasics.co.uk/RTL.asp? Name=FloatToStrF
特别是这个: `ShowMessage('Using 8,4 = '+FloatToStrF(amount1, ffFixed, 8, 4));
会表明你可以使用这样的东西:
Try here: http://www.delphibasics.co.uk/RTL.asp?Name=FloatToStrF
Particularly this one: `ShowMessage('Using 8,4 = '+FloatToStrF(amount1, ffFixed, 8, 4));
would indicate you can use something like this: