# Round Decimal in WebApp

**URL:** <https://forum.xojo.com/t/round-decimal-in-webapp/21747>\
**Category:** Web\
**Created:** [January 21, 2015, 10:46am UTC](https://forum.xojo.com/t/round-decimal-in-webapp/21747 "2015-01-21T10:46:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lars\_Lehmann](https://forum.xojo.com/user_avatar/forum.xojo.com/lars_lehmann/32/11818_2.png) [@Lars\_Lehmann](https://forum.xojo.com/u/Lars_Lehmann)\
**Post date:** [January 21, 2015, 10:46am UTC](https://forum.xojo.com/t/round-decimal-in-webapp/21747/1 "2015-01-21T10:46:01Z")

</div>

Hi,  
I have a decimal like `0.9876`  
I want to round this two digits after the point: `0.99`

I read about the floor, ceil and round - funktion  
But no function gives me what I want.

Whats the solution?

-Lars

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [January 21, 2015, 11:26am UTC](https://forum.xojo.com/t/round-decimal-in-webapp/21747/2 "2015-01-21T11:26:39Z")

</div>

[quote=160923:@Lars Lehmann]Hi,  
I have a decimal like `0.9876`  
I want to round this two digits after the point: `0.99`

I read about the floor, ceil and round - funktion  
But no function gives me what I want.

Whats the solution?

-Lars[/quote]

[code] dim d as double

d=ceil(0.9876\*100)/100

msgbox str(d)[/code]

You will need to decide when using Floor and Ceil is necessary. For instance, when the third decimal \> 5 use Ceil, and otherwise use Floor, so 0.9876 gives 0.99 and 0.9846 gives 0.98.

---

<div class="post-metadata">

**Author:** ![Lars\_Lehmann](https://forum.xojo.com/user_avatar/forum.xojo.com/lars_lehmann/32/11818_2.png) [@Lars\_Lehmann](https://forum.xojo.com/u/Lars_Lehmann)\
**Post date:** [January 21, 2015, 11:37am UTC](https://forum.xojo.com/t/round-decimal-in-webapp/21747/3 "2015-01-21T11:37:19Z")

</div>

lol there’s no ready function?

I’ve probably bite the bullet and write my own function 😕

---

<div class="post-metadata">

**Author:** ![Jay\_Madren](https://forum.xojo.com/user_avatar/forum.xojo.com/jay_madren/32/6425_2.png) [@Jay\_Madren](https://forum.xojo.com/u/Jay_Madren)\
**Post date:** [January 21, 2015, 12:16pm UTC](https://forum.xojo.com/t/round-decimal-in-webapp/21747/4 "2015-01-21T12:16:16Z")

</div>

> [@160943:@Lars Lehmann](#):
>
> lol there’s no ready function?

Of course there is: [Round](http://documentation.xojo.com/index.php/Round). But you’ll still have to temporarily “move” the decimal like MIchel does.

Or you could use [Format](http://documentation.xojo.com/index.php/Format), but you’ll have to convert it back to a double, if needed :

`dim d as double
d = Val(Format(0.9876,"#####0,##"))`

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [January 21, 2015, 1:35pm UTC](https://forum.xojo.com/t/round-decimal-in-webapp/21747/5 "2015-01-21T13:35:46Z")

</div>

[quote=160943:@Lars Lehmann]lol there’s no ready function?

I’ve probably bite the bullet and write my own function :/[/quote]

What is wrong with the two lines I posted ? ? ?

---

<div class="post-metadata">

**Author:** ![Lars\_Lehmann](https://forum.xojo.com/user_avatar/forum.xojo.com/lars_lehmann/32/11818_2.png) [@Lars\_Lehmann](https://forum.xojo.com/u/Lars_Lehmann)\
**Post date:** [January 22, 2015, 7:32am UTC](https://forum.xojo.com/t/round-decimal-in-webapp/21747/6 "2015-01-22T07:32:13Z")

</div>

nothing @Michel Bujardet  
Thanks! I only thought theres a build-in function 😉

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [January 22, 2015, 8:10am UTC](https://forum.xojo.com/t/round-decimal-in-webapp/21747/7 "2015-01-22T08:10:45Z")

</div>

[quote=161282:@Lars Lehmann]nothing @Michel Bujardet  
Thanks! I only thought theres a build-in function ;)[/quote]

From what I can see, Round [http://documentation.xojo.com/index.php/Round](http://documentation.xojo.com/index.php/Round) is exactly that. Except you cannot decide which kind of rounding you apply. I think in particular about such things as the kind of rounding used for petty cash.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:35pm UTC](https://forum.xojo.com/t/round-decimal-in-webapp/21747/8 "2020-10-29T17:35:23Z")

</div>


