# **[](https://en.cppreference.com/w/cpp/header/ratio)** provides compile-time rational number arithmetic via `std::ratio`. Ratios are commonly used as template parameters for durations (e.g., `std::chrono::milliseconds` is `std::ratio<1, 1000>`). Most code doesn't use this directly; you encounter it when working with `std::chrono::duration`. ## Example This example defines and uses ratio types to represent milliseconds and microseconds, querying their numerator and denominator. ```cpp // compile: g++ -std=c++11 -o ratioexample ratioexample.cpp // run: ./ratioexample // description: compile-time rational arithmetic #include #include using milliseconds = std::ratio<1, 1000>; using microseconds = std::ratio<1, 1000000>; int main() { std::cout << "milliseconds: " << milliseconds::num << "/" << milliseconds::den << "\n"; std::cout << "microseconds: " << microseconds::num << "/" << microseconds::den << "\n"; using mega = std::ratio<1000000>; std::cout << "mega: " << mega::num << "/" << mega::den << "\n"; return 0; } ```