Solved

# truncating a decimal no.  in C++

Posted on 2004-11-10
2,673 Views
I wanted to truncate a decimal no in c++
e.g

#include <iostream>
using namespace std;

int main()
{
float b;
b = 4.34534;
.I wanted to truncate b to "4".
0
Question by:chataholic4real
1 Comment

LVL 13

Accepted Solution

In this case you can use floor ():

float btrunc = floor (b);

The more general case where you truncate to some digits after the decimal point:

float btrunc = 1. / 1000 * floor ( b * 1000); // this is for 3 digits left replace 1000 with appropriate number for other number of digits.

0

## Featured Post

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.