# Quick SQL question - how to show a number and force 2 decimal places

**URL:** <https://boards.straightdope.com/t/quick-sql-question-how-to-show-a-number-and-force-2-decimal-places/545546>\
**Category:** Factual Questions\
**Created:** [July 4, 2010, 7:29pm UTC](https://boards.straightdope.com/t/quick-sql-question-how-to-show-a-number-and-force-2-decimal-places/545546 "2010-07-04T19:29:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [July 4, 2010, 7:29pm UTC](https://boards.straightdope.com/t/quick-sql-question-how-to-show-a-number-and-force-2-decimal-places/545546/1 "2010-07-04T19:29:40Z")

</div>

For example.

If I have a value of 3.6 I want it to display as 3.60.

I am sure it’s simple but I couldn’t find the answer on google.  
Basically I’m trying to display money amounts. But when I do convert(money,[stuff to convert]) it displays anything that is a multiple of ten units without the extra zero in the second decimal place. For display purposes I want it to display the zero.

---

<div class="post-metadata">

**Author:** ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)\
**Post date:** [July 4, 2010, 7:42pm UTC](https://boards.straightdope.com/t/quick-sql-question-how-to-show-a-number-and-force-2-decimal-places/545546/2 "2010-07-04T19:42:34Z")

</div>

nevermind. I found the answer…

convert(decimal(10,2),[thing I’m converting])

---

<div class="post-metadata">

**Author:** ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)\
**Post date:** [July 4, 2010, 7:54pm UTC](https://boards.straightdope.com/t/quick-sql-question-how-to-show-a-number-and-force-2-decimal-places/545546/3 "2010-07-04T19:54:17Z")

</div>

For future reference, you should always store money as an integer number of cents (or pence) and not as a float. It’s much easier to do all your accounting math and divide by 100 only when you need to display a value to the user.

ETA: If your database has a built-in money type, I believe that’s essentially what they do under the hood.

---

<div class="post-metadata">

**Author:** ![BorgHunter](https://avatars.discourse-cdn.com/v4/letter/b/7c8e57/32.png) [@BorgHunter](https://boards.straightdope.com/u/BorgHunter)\
**Post date:** [July 5, 2010, 10:23pm UTC](https://boards.straightdope.com/t/quick-sql-question-how-to-show-a-number-and-force-2-decimal-places/545546/4 "2010-07-05T22:23:31Z")

</div>

> [@friedo](#):
>
> For future reference, you should always store money as an integer number of cents (or pence) and not as a float. It’s much easier to do all your accounting math and divide by 100 only when you need to display a value to the user.

It also avoids problems like some UI declaring that a widget is $14.9999999999999999994 instead of $15.

---

<div class="post-metadata">

**Author:** ![wolfman](https://avatars.discourse-cdn.com/v4/letter/w/a8b319/32.png) [@wolfman](https://boards.straightdope.com/u/wolfman)\
**Post date:** [July 5, 2010, 10:34pm UTC](https://boards.straightdope.com/t/quick-sql-question-how-to-show-a-number-and-force-2-decimal-places/545546/5 "2010-07-05T22:34:48Z")

</div>

> [@friedo](#):
>
> For future reference, you should always store money as an integer number of cents (or pence) and not as a float. It’s much easier to do all your accounting math and divide by 100 only when you need to display a value to the user.
> 
> ETA: If your database has a built-in money type, I believe that’s essentially what they do under the hood.

Hehe I was gonna give that lecture. As a contractor lately I can’t count the number of times I have been tasked to track down a variance only to find that money is being stored as a float or with too much precision and the bits add up to something that was never there.
