Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

What is the best data type to use for currency

Hi guys,
What is the best data type to use for currency. I ask this because currently I am using 'Single' data type however it often gives me 15.4999999, etc. so I have to keep rounding that to 2 decimal places and formatting. That seems so inefficient, especially if there is significant amount of computation being done.

Any suggestions?

/Michael
0
gem56
Asked:
gem56
  • 2
2 Solutions
 
SethiCommented:
Decimal.
0
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
the documentation recommends to use the Decimal Type
0
 
SethiCommented:
You can always use the Format function to curtail the numer of digits you want to see after the decimanl like this:
Dim decNumber as Decimal
decNumber = 15.4999999
decNumber.ToString.Format("#,###.00")
0
 
gem56Author Commented:
Tanks for that guys.

I considered using Decimal type but thought in light of its size (8 bytes) that Single was more efficient to use (4 bytes). I'll try Decimal type but it seems I can't get away from using Round and Format functions. It's OK for now but in future if I need to do more repetitive computation I may feel different.

/Michael
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now