-8

I'm learning c++, and I need type values which aren't int for decimals. Anyone have some?

I have tried dec and decimal but they don't work.

this is my code right now:

dec Number = 31;

Thanks for having a look at my question!

  • How about `double`? – Beta Apr 04 '19 at 04:06
  • 2
    @Beta Never for money. When you need precision, never use floating point. If you don't have access to a proper decimal type, use an integer nevertheless; e.g. to represent $6.32 dollars, use 632 cents instead. – Amadan Apr 04 '19 at 04:08
  • Are you talking about real numbers vs integral numbers? – R Sahu Apr 04 '19 at 04:08
  • 2
    @Amadan: Who said anything about money? – Beta Apr 04 '19 at 04:08
  • 1
    @Beta: I did. Because there are times when `float` or `double` is great, and there's times when it's a felony (and everything in between). Adding a warning to "how about `double`" is just common sense. – Amadan Apr 04 '19 at 04:10
  • @Amadan: That's absurd. No data type is good for all applications, and adding warnings to *every possible suggestion* is just wasting everyone's time. – Beta Apr 04 '19 at 04:13
  • 3
    @Beta: Given that OP is asking for "decimal", which names a data type specifically designed to represent fixed-point real number, and almost exclusively used to avoid problems with floating point arithmetics, and was likely trying to use [C++ extensions that implement it](https://stackoverflow.com/questions/14096026/c-decimal-data-types)... I'd say the warning is very relevant. – Amadan Apr 04 '19 at 04:18
  • 1
    "Decimal" doesn't necessarily imply that the OP knows that "decimal" is a type. It could just mean he wants digits after a '.'. A floating point type is the obvious first answer. Either way, both answers are making some assumptions. Original poster, please be a bit more detailed in your requirements. – Steve Apr 04 '19 at 04:40

1 Answers1

0

You can use double or float

Hope this helps!