Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Itos Function

Status
Not open for further replies.

MuzamilEETC

Mechanical
Joined
Nov 16, 2010
Messages
31
Location
JP
Hi,

As we know Itos function used to convert Integer to string. When we use this to a Real number having 14 decimal values it round off to a single digit. Can we use this to show as 2 decimal places.

Ceil and floor maintains the integer data type requirement is to convert to string and change from 14 to 2 decimal places.

Thanks and regards
Muzamil
 
I have done this in the past. The approach is to first make a string variable equal to the integer portion of the real number plus a "." (or comma if using metric). Then you take the portion of the real number after the decimal point and multiply it by 10 and take the integer portion if it is 1 or more and addit to the right of the period. This would be continued up to the number of decimal places desired. Be sure to add code to get the number rounded off for the last decimal place.

Peter Stockhausen
Senior Design Analyst (Checker)
Infotech Aerospace Services
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top