四舍五入到9 [英] rounding to 9's

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

问题描述

我正在尝试将我的货币字符串舍入到9结束。这是一个

定价应用程序。

这是我的功能'' m用于获取货币项目:

FormatCurrency(BoxCost ,,,, TriState.True)


如果项目是41.87我想要申请把它带到41.89


如果一个项目是41.84我希望应用程序舍入到41.79


有谁知道我怎么做这个?

i''m trying to round my currency string to end in 9. it''s for a
pricing application.
this is the function i''m using to get the item in currency:
FormatCurrency(BoxCost, , , , TriState.True)

if an item is 41.87 i want the application to bring it up to 41.89

if an item is 41.84 i want the application to round down to 41.79

does anyone know how i could do this?

推荐答案

7月6日下午4:06,jdrott1< jonathandr ... @ gmail.comwrote:
On Jul 6, 4:06 pm, jdrott1 <jonathandr...@gmail.comwrote:

我试图将我的货币字符串舍入到9结束。这是一个

定价应用程序。

这是我用来获取货币项目的功能:

FormatCurrency(BoxCost ,,,, TriState.True)


如果项目是41.87,我希望申请将其提高到41.89


如果项目是41.84我想要将应用程序舍入到41.79


有谁知道我怎么能这样做?
i''m trying to round my currency string to end in 9. it''s for a
pricing application.
this is the function i''m using to get the item in currency:
FormatCurrency(BoxCost, , , , TriState.True)

if an item is 41.87 i want the application to bring it up to 41.89

if an item is 41.84 i want the application to round down to 41.79

does anyone know how i could do this?



您必须手动完成 - 只需解析小数后的第二位数字,然后相应地调整值。


谢谢,


Seth Rowe

You would have to do it manually - just parse the second digit after
the decimal and adjust the value accordingly.

Thanks,

Seth Rowe


嗨Jonathan -


您是否尝试过四舍五入到最近的十分之一并减去一个

hundreth?


将myVal变为双倍

myVal = 41.87

myVal = Math.Round(myVal,1) - 0.01

Debug.WriteLine(myVal)''返回41.89


myVal = 41.84

myVal = Math.Round(myVal,1) - 0.01

Debug.WriteLine(myVal)''返回41.79

....有时最简单的方法效果最好。


快乐编码,


-Mark

Hi Jonathan -

Have you tried rounding to the nearest tenth and subtracting one
hundreth?

Dim myVal As Double
myVal = 41.87
myVal = Math.Round(myVal, 1) - 0.01
Debug.WriteLine(myVal) ''Returns 41.89

myVal = 41.84
myVal = Math.Round(myVal, 1) - 0.01
Debug.WriteLine(myVal) ''Returns 41.79

....sometimes the simplest approaches work the best.

Happy Coding,

-Mark


7月6日下午3:50,Mark S. Milley,MCSD(BinarySwitch)

< mark.mil ... @ binaryswitch.comwrote:
On Jul 6, 3:50 pm, "Mark S. Milley, MCSD (BinarySwitch)"
<mark.mil...@binaryswitch.comwrote:

嗨Jo nathan -


您是否尝试过四舍五入到最近的十分之一并减去一个

hundreth?


Dim myVal As Double

myVal = 41.87

myVal = Math.Round(myVal,1) - 0.01

Debug.WriteLine(myVal)''返回41.89


myVal = 41.84

myVal = Math.Round(myVal,1) - 0.01

Debug.WriteLine(myVal)' '返回41.79


...有时候最简单的方法效果最好。


快乐编码,


-Mark
Hi Jonathan -

Have you tried rounding to the nearest tenth and subtracting one
hundreth?

Dim myVal As Double
myVal = 41.87
myVal = Math.Round(myVal, 1) - 0.01
Debug.WriteLine(myVal) ''Returns 41.89

myVal = 41.84
myVal = Math.Round(myVal, 1) - 0.01
Debug.WriteLine(myVal) ''Returns 41.79

...sometimes the simplest approaches work the best.

Happy Coding,

-Mark



我会试一试。谢谢。

i''ll give it a try. thanks.


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

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