QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
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 {
24
25 namespace detail {
26
27 std::ostream& operator<<(std::ostream& out,
28 const ordinal_holder& holder) {
29 Size n = holder.n;
30 out << n;
31 if (n == Size(11) || n == Size(12) || n == Size(13)) {
32 out << "th";
33 } else {
34 switch (n % 10) {
35 case 1: out << "st"; break;
36 case 2: out << "nd"; break;
37 case 3: out << "rd"; break;
38 default: out << "th";
39 }
40 }
41 return out;
42 }
43
44 std::ostream& operator<<(std::ostream& out,
45 const percent_holder& holder) {
46 std::ios::fmtflags flags = out.flags();
47 Size width = (Size)out.width();
48 if (width > 2)
49 out.width(width-2); // eat space used by percent sign
50 out << std::fixed;
51 if (holder.value == Null<Real>())
52 out << "null";
53 else
54 out << holder.value * 100.0 << " %";
55 out.flags(flags);
56 return out;
57 }
58
59 }
60
61}
62
template class providing a null value for a given type.
Definition: null.hpp:76
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
Definition: any.hpp:35