File size: 7,393 Bytes
845bdb9
 
 
 
405b09e
845bdb9
405b09e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
01ad28b
405b09e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
---
license: apache-2.0
tags:
- height-conversion
- utility
- measurement
- unit-conversion
language:
- en
- vi
---

# 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

```bash
pip install height-conversion-tool
```

Or clone this repository:

```bash
git clone https://huggingface.co/NuBest/height-conversion-tool
cd height-conversion-tool
pip install -r requirements.txt
```

## Quick Start

### Python Usage

```python
from height_converter import HeightConverter

# Initialize converter
converter = HeightConverter()

# Convert from feet/inches to centimeters
height_cm = converter.feet_to_cm(5, 10)  # 5 feet 10 inches
print(f"Height: {height_cm} cm")  # Output: Height: 177.8 cm

# Convert from centimeters to feet/inches
feet, inches = converter.cm_to_feet(180)
print(f"Height: {feet}'{inches}\"")  # Output: Height: 5'11"

# String input format
result = converter.convert("5'10\"", to_unit="cm")
print(result)  # Output: 177.8 cm
```

### Command Line Usage

```bash
# Convert height
python height_converter.py --input "5'10\"" --output cm

# Multiple conversions
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:
  - `meters`: Height in meters
- 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

```python
from height_converter import HeightConverter

converter = HeightConverter()

# Convert 6 feet to centimeters
result = converter.feet_to_cm(6, 0)
print(f"6 feet = {result} cm")  # Output: 6 feet = 182.88 cm
```

### Example 2: Batch Conversion

```python
heights_cm = [150, 160, 170, 180, 190]

for height in heights_cm:
    feet, inches = converter.cm_to_feet(height)
    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

```python
from flask import Flask, request, jsonify
from height_converter import HeightConverter

app = Flask(__name__)
converter = HeightConverter()

@app.route('/convert', methods=['POST'])
def convert_height():
    data = request.json
    input_height = data.get('height')
    to_unit = data.get('to_unit', 'cm')
    
    result = converter.convert(input_height, to_unit)
    return jsonify({'result': result})

if __name__ == '__main__':
    app.run(debug=True)
```

## Testing

Run the test suite:

```bash
python -m pytest tests/
```

Run specific tests:

```bash
python -m pytest tests/test_converter.py -v
```

## Contributing

We welcome contributions! Please follow these steps:

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

### Development Setup

```bash
# Clone repository
git clone https://huggingface.co/NuBest/height-conversion-tool
cd height-conversion-tool

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install development dependencies
pip install -r requirements-dev.txt

# Run tests
pytest
```

## License

This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.

## Citation

If you use this tool in your research or project, please cite:

```bibtex
@software{height_conversion_tool,
  author = {NuBest},
  title = {Height Conversion Tool},
  year = {2025},
  url = {https://huggingface.co/NuBest/height-conversion-tool}
}
```

## Support

- **Issues**: [GitHub Issues](https://huggingface.co/NuBest/height-conversion-tool/discussions)
- **Discussions**: [Community Forum](https://huggingface.co/NuBest/height-conversion-tool/discussions)
- **Email**: support@nubest.com
- **Website**: https://www.nubest.com/

## 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