QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
dataformatters.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2005 StatPro Italia srl
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
21#include <ostream>
22
23namespace QuantLib::detail {
24
25 std::ostream& operator<<(std::ostream& out,
26 const ordinal_holder& holder) {
27 Size n = holder.n;
28 out << n;
29 if (n == Size(11) || n == Size(12) || n == Size(13)) {
30 out << "th";
31 } else {
32 switch (n % 10) {
33 case 1: out << "st"; break;
34 case 2: out << "nd"; break;
35 case 3: out << "rd"; break;
36 default: out << "th";
37 }
38 }
39 return out;
40 }
41
42 std::ostream& operator<<(std::ostream& out,
43 const percent_holder& holder) {
44 std::ios::fmtflags flags = out.flags();
45 Size width = (Size)out.width();
46 if (width > 2)
47 out.width(width-2); // eat space used by percent sign
48 out << std::fixed;
49 if (holder.value == Null<Real>())
50 out << "null";
51 else
52 out << holder.value * 100.0 << " %";
53 out.flags(flags);
54 return out;
55 }
56
57 }
58
template class providing a null value for a given type.
Definition: null.hpp:59
output manipulators
std::size_t Size
size of a container
Definition: types.hpp:58
std::ostream & operator<<(std::ostream &out, const short_date_holder &holder)
Definition: date.cpp:894