Currency Properties
Overview
Microsoft Project lets users set which currency costs are shown in, in a project. They can define set the currency code, numbers after the decimal point and currency symbol so that costs show in an easy to read and intuitive way. Aspose.Tasks for C++ supports these features and provides a series of properties that help developers set and control currency properties. This topic explains how to read currency properties, and how to set them.
Aspose.Tasks provides properties exposed by the Project class, for managing currency properties:
- CurrencyCode: the three-letter currency code, for example, USD, GBP or AUD, passed as a string.
- CurrencyDigits: the number of numbers after the decimal point, for example, 2 (100.00) or 3 (100.000), passed as an integer.
- CurrencySymbol: the currency symbol, for example, $ or £, passed as a string.
- CurrencySymbolPosition: the position of the currency symbol, for example before ($100) or after (100$). CurrencySymbolPosition takes a value from the CurrencySymbolPositionType enumeration.
Reading Currency Properties
The code example given below demonstrates how to read a project’s currency properties.
1// The path to the documents directory.
2System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
3
4// Create project instance
5System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"ReadCurrencyProperties.mpp");
6
7// Display currency properties
8System::Console::WriteLine(System::String(u"Currency Code : ") + System::ObjectExt::ToString(project->Get<System::String>(Prj::CurrencyCode())));
9System::Console::WriteLine(System::String(u"<br>Currency Digits : ") + System::Convert::ToString(project->Get<int32_t>(Prj::CurrencyDigits())));
10System::Console::WriteLine(System::String(u"<br>Currency Symbol : ") + System::ObjectExt::ToString(project->Get<System::String>(Prj::CurrencySymbol())));
11System::Console::WriteLine(System::String(u"Currency Symbol Position") + System::ObjectExt::ToString(project->Get<CurrencySymbolPositionType>(Prj::CurrencySymbolPosition())));
Writing Currency Properties
To see the currency properties in Microsoft Project:
- Open the project file.
- On the Tools menu, select Options.
- Click the View tab and for Project 2016 Display. It will look like the one shown below.
The code example given below demonstrates how to write currency properties to the project.
1// The path to the documents directory.
2System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
3
4// Create a project instance
5System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"WriteCurrencyProperties.mpp");
6
7// Set currency properties
8project->Set<System::String>(Prj::CurrencyCode(), u"AUD");
9project->Set<int32_t>(Prj::CurrencyDigits(), 2);
10project->Set<System::String>(Prj::CurrencySymbol(), u"$");
11project->Set<CurrencySymbolPositionType>(Prj::CurrencySymbolPosition(), Aspose::Tasks::CurrencySymbolPositionType::After);
12
13// Save the project as XML project file
14project->Save(dataDir + u"WriteCurrencyProperties_out.xml", Aspose::Tasks::Saving::SaveFileFormat::XML);