可变小数位 [英] Variable decimal places

查看:68
本文介绍了可变小数位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi,
Just started creating a Visual Basic project in Visual Studio 2015 that tracks medical lab results.  The Lab table consists of, in part:

    Test Name
    Date
    Result

The result field will contain numerical values for different tests. However, the decimal places (places right of decimal point), or Scale could be anywhere from 0 to 4 depending on the test.  I don’t want to set the Scale to 4 for all tests because it would look silly for results that are returned in whole numbers only. i.e. the value 1324 world return as 1324.0000, or the value 13.06 would return 13.0600 and so forth.

What is the best way work with this issue?





我尝试了什么:



我尝试为不同的小数位创建不同的表,但显然返回数据时不起作用。



What I have tried:

I tried creating different tables for different the different decimal places but obviously what won't work when returning data.

推荐答案

我会在数据库中保存和存储尽可能多的精度,因为我可以从测试结果返回 - 这些数据永远不会被更改/重新格式化 - 它是报告的唯一源数据,但原始人应该需要向后工作。



它是测试结果的报告(对于人类而言),你担心看起来像一个人 - 一位同事和我写了一个格式化程序(用于pdf报告)一段时间后根据数字的比例改变了小数点数 - 正如你所建议的那样1324.0000是荒谬的,如果(例如)它只是一个整体数字(所以小数位也可能是'0'),而13.24可能需要小数位= 2.您可以根据测试名称设置一个例程来格式化输出数据 - 也就是说 - 我们根据数字的比例使用了直觉 - 即,比例越大,小数点的数量越小,反之亦然,达到我们正在处理的限制
I would keep and store as much precision in the database as I can/is returned from the result's of the test - this data never gets altered/re-formatted - its only source data for the reports, but pristine should someone need to work backwards.

Its the 'reporting' of the test results (to a human) where you are worried about 'how a figure looks' - a colleague and I wrote a formatter (for a pdf report) library a while back that altered the # of decimal points according to the scale of the number - as you've suggested 1324.0000 is ridiculous if (for example) its only a whole number (so decimal places may as well be '0'), whereas 13.24 may need decimal places = 2. You could have a routine to format the figures for output based on the 'test name' perhaps - iirc we've used a 'gut feel' based on the scale of the number - ie, the larger the scale, the smaller the number of decimal points and vice versa, up to limits that make sense for what we are dealing with


如果有一个表来存储医学测试结果,还有一个列表测试名称表示每个测试所需的格式?

之后,只需在显示测试结果时选择格式。
What about having a single table to store medical test results, and a list of test names indicating the format you want for each test ?
After that it is just a matter of choosing the format when displaying the test result.


这篇关于可变小数位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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