Height Conversion Tool
A simple and efficient tool for converting height measurements between different units (feet/inches, centimeters, meters).
Model Overview
This tool provides accurate height conversions between various measurement systems commonly used around the world. It supports bidirectional conversions and handles multiple input formats.
Features
Multiple Unit Support : Convert between feet/inches, centimeters, and meters
Flexible Input : Accepts various input formats (e.g., "5'10"", "178 cm", "1.78 m")
High Accuracy : Maintains precision across conversions
Easy to Use : Simple API with clear documentation
Bilingual : Supports English and Vietnamese
Supported Conversions
From To Example Feet & Inches Centimeters 5'10" → 177.8 cm Centimeters Feet & Inches 180 cm → 5'11" Meters Feet & Inches 1.75 m → 5'9" Feet & Inches Meters 6'0" → 1.83 m Centimeters Meters 170 cm → 1.7 m
Installation
pip install height-conversion-tool
Or clone this repository:
1 git clone https://huggingface.co/NuBest/height-conversion-tool
2 cd height-conversion-tool
3 pip install -r requirements.txt
Quick Start
Python Usage
1 from height_converter import HeightConverter
2
3 # Initialize converter
4 converter = HeightConverter ( )
5
6 # Convert from feet/inches to centimeters
7 height_cm = converter . feet_to_cm ( 5 , 10 ) # 5 feet 10 inches
8 print ( f"Height: { height_cm } cm" ) # Output: Height: 177.8 cm
9
10 # Convert from centimeters to feet/inches
11 feet , inches = converter . cm_to_feet ( 180 )
12 print ( f"Height: { feet } ' { inches } \"" ) # Output: Height: 5'11"
13
14 # String input format
15 result = converter . convert ( "5'10\"" , to_unit = "cm" )
16 print ( result ) # Output: 177.8 cm
Command Line Usage
1 # Convert height
2 python height_converter.py --input "5'10 \" " --output cm
3
4 # Multiple conversions
5 python height_converter.py --input 180 --from cm --to feet
API Reference
HeightConverter Class
Methods
feet_to_cm(feet: int, inches: float = 0) -> float
Converts feet and inches to centimeters
Parameters:
feet: Number of feet
inches: Number of inches (optional, default: 0)
Returns: Height in centimeters
cm_to_feet(cm: float) -> tuple[int, float]
Converts centimeters to feet and inches
Parameters:
cm: Height in centimeters
Returns: Tuple of (feet, inches)
meters_to_feet(meters: float) -> tuple[int, float]
Converts meters to feet and inches
Parameters:
Returns: Tuple of (feet, inches)
convert(input_str: str, to_unit: str = "cm") -> str
Flexible conversion from string input
Parameters:
input_str: Height string (e.g., "5'10"", "180cm", "1.8m")
to_unit: Target unit ("cm", "feet", "meters")
Returns: Converted height as string
Use Cases
Healthcare : Converting patient height measurements between metric and imperial systems
Fitness Apps : Standardizing height inputs across different regions
E-commerce : Converting size charts for international customers
Travel Apps : Helping users understand height requirements in different countries
Education : Teaching measurement conversions
Technical Details
Conversion Formulas
1 inch = 2.54 cm
1 foot = 12 inches = 30.48 cm
1 meter = 100 cm = 3.28084 feet
Accuracy
The tool maintains precision up to 2 decimal places for centimeters and meters, and up to 1 decimal place for inches.
Examples
Example 1: Basic Conversion
1 from height_converter import HeightConverter
2
3 converter = HeightConverter ( )
4
5 # Convert 6 feet to centimeters
6 result = converter . feet_to_cm ( 6 , 0 )
7 print ( f"6 feet = { result } cm" ) # Output: 6 feet = 182.88 cm
Example 2: Batch Conversion
1 heights_cm = [ 150 , 160 , 170 , 180 , 190 ]
2
3 for height in heights_cm :
4 feet , inches = converter . cm_to_feet ( height )
5 print ( f" { height } cm = { feet } ' { inches : .1f } \"" )
Output:
150 cm = 4'11.1"
160 cm = 5'3.0"
170 cm = 5'7.0"
180 cm = 5'10.9"
190 cm = 6'2.8"
Example 3: Web Integration
1 from flask import Flask , request , jsonify
2 from height_converter import HeightConverter
3
4 app = Flask ( __name__ )
5 converter = HeightConverter ( )
6
7 @app . route ( '/convert' , methods = [ 'POST' ] )
8 def convert_height ( ) :
9 data = request . json
10 input_height = data . get ( 'height' )
11 to_unit = data . get ( 'to_unit' , 'cm' )
12
13 result = converter . convert ( input_height , to_unit )
14 return jsonify ( { 'result' : result } )
15
16 if __name__ == '__main__' :
17 app . run ( debug = True )
Testing
Run the test suite:
Run specific tests:
python -m pytest tests/test_converter.py -v
Contributing
We welcome contributions! Please follow these steps:
Fork the repository
Create a feature branch (git checkout -b feature/amazing-feature)
Commit your changes (git commit -m 'Add some amazing feature')
Push to the branch (git push origin feature/amazing-feature)
Open a Pull Request
Development Setup
1 # Clone repository
2 git clone https://huggingface.co/NuBest/height-conversion-tool
3 cd height-conversion-tool
4
5 # Create virtual environment
6 python -m venv venv
7 source venv/bin/activate # On Windows: venv\Scripts\activate
8
9 # Install development dependencies
10 pip install -r requirements-dev.txt
11
12 # Run tests
13 pytest
License
This project is licensed under the Apache License 2.0 - see the
LICENSE file for details.
Citation
If you use this tool in your research or project, please cite:
1 @software{height_conversion_tool,
2 author = {NuBest},
3 title = {Height Conversion Tool},
4 year = {2025},
5 url = {https://huggingface.co/NuBest/height-conversion-tool}
6 }
Support
Changelog
Version 1.0.0 (2025-01-29)
Initial release
Support for feet/inches, centimeters, and meters
Command line interface
Python API
Comprehensive test suite
Acknowledgments
Built with Python 3.8+
Inspired by the need for accurate height conversions in international applications
Special thanks to the Hugging Face community
FAQ
Q: What's the maximum height that can be converted?
A: The tool supports heights up to 999 cm (32'9") to cover all practical use cases.
Q: How accurate are the conversions?
A: Conversions maintain precision up to 2 decimal places, which is sufficient for all practical purposes.
Q: Can I use this in a commercial application?
A: Yes, the Apache 2.0 license allows commercial use with proper attribution.
Q: Does it support other units like yards or kilometers?
A: Currently, the tool focuses on the most commonly used units (feet/inches, cm, meters). Additional units may be added in future versions.
Q: How do I handle invalid input?
A: The tool includes input validation and raises clear error messages for invalid inputs.
Made with ❤️ by NuBest Team