Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Show all

Numeric Types

Updated on 2024-08-20 GMT+08:00

Table 1 lists the common APIs for numeric (numeric or decimal) data provided by the ECPG.

Table 1 Common numeric type APIs

API

Description

Remarks

numeric* PGTYPESnumeric_new(void)

Requests a pointer to a newly allocated numeric variable.

This function creates a numeric variable on the heap. The return value is of the numeric* type.

decimal* PGTYPESdecimal_new(void)

Requests a pointer to a newly allocated decimal variable.

This function creates a decimal variable on the heap. The return value is of the decimal* type.

void PGTYPESnumeric_free(numeric* var)

Frees the memory of a variable of the numeric type.

This function frees a numeric* variable created by using the PGTYPESnumeric_new function.

void PGTYPESdecimal_free(decimal*)

Frees the memory of a variable of the decimal type.

This function frees a decimal* variable created by using the PGTYPESdecimal_new function.

numeric* PGTYPESnumeric_from_asc(char* str, char** endptr)

Converts a string to the numeric type.

For example, the valid formats are –2, .794, +3.44, 592.49E07, or –32.84e–4. If the value could be parsed successfully, a valid pointer is returned; otherwise, a null pointer is returned. ECPG only parses complete character strings. Currently, ECPG does not support storing the address of the first invalid character in *endptr. However, endptr can be set to null.

char* PGTYPESnumeric_to_asc(numeric* num, int dscale)

Returns a pointer to a string allocated by malloc that contains the string representation of the numeric type num.

The numeric value will be printed using dscale decimal places and will be rounded if necessary.

int PGTYPESnumeric_add(numeric* var1, numeric* var2, numeric* result)

Adds two numeric variables to the third numeric variable.

This function adds the variables var1 and var2 to the result variable result. The function returns 0 on success and –1 in case of error.

int PGTYPESnumeric_sub(numeric* var1, numeric* var2, numeric* result)

Subtracts two numeric variables and returns the result to the third numeric variable.

This function subtracts var2 from var1. The result of this operation is stored in the variable result. The function returns 0 on success and –1 in case of error.

int PGTYPESnumeric_mul(numeric* var1, numeric* var2, numeric* result)

Multiplies two numeric variables and returns the result to the third numeric variable.

This function multiplies variables var1 and var2. The result of this operation is stored in the variable result. The function returns 0 on success and –1 in case of error.

int PGTYPESnumeric_div(numeric* var1, numeric* var2, numeric* result)

Divides two numeric variables and returns the result to the third numeric variable.

This function divides variable var1 by variable var2. The result of this operation is stored in the variable result. The function returns 0 on success and –1 in case of error.

int PGTYPESnumeric_cmp(numeric* var1, numeric* var2)

Compares two numeric variables.

This function compares two numeric variables. If an error occurs, INT_MAX is returned. On success, this function returns one of the following three possible results:
  • If var1 is greater than var2, 1 is returned.
  • If var1 is smaller than var2, –1 is returned.
  • If var1 and var2 are equal, 0 is returned.

int PGTYPESnumeric_from_int(signed int int_val, numeric* var)

Converts an int variable into a numeric variable.

This function accepts a signed int variable and stores it in the numeric variable var. The function returns 0 on success and –1 in case of failure.

int PGTYPESnumeric_from_long(signed long int long_val, numeric* var)

Converts a long int variable into a numeric variable.

This function accepts a long int variable and stores it in the numeric variable var. The function returns 0 on success and –1 in case of failure.

int PGTYPESnumeric_copy(numeric* src, numeric* dst)

Copies a numeric variable to another one.

This function copies the value of the variable that src points to into the variable that dst points to. The function returns 0 on success and –1 in case of error.

int PGTYPESnumeric_from_double(double d, numeric* dst)

Converts a double-precision variable into a numeric variable.

This function accepts a double-precision variable and stores the result in the variable that dst points to. The function returns 0 on success and –1 in case of error.

int PGTYPESnumeric_to_double(numeric* nv, double* dp)

Converts a numeric variable into a double-precision variable.

This function converts the numeric value in the variable that nv points to into a double-precision variable that dp points to. The function returns 0 on success and –1 in case of error (or overflow). When overflow occurs, the global variable errno is additionally set to PGTYPES_NUM_OVERFLOW.

int PGTYPESnumeric_to_int(numeric* nv, int* ip)

Converts a numeric variable into an int variable.

This function converts the numeric value in the variable that nv points to into an int variable that the IP address points to. The function returns 0 on success and –1 in case of error (or overflow). When overflow occurs, the global variable errno is additionally set to PGTYPES_NUM_OVERFLOW.

int PGTYPESnumeric_to_long(numeric* nv, long* ip)

Converts a numeric variable into a long int variable.

This function converts the numeric value in the variable that nv points to into a long int variable that the IP points to. The function returns 0 on success and –1 in case of error (or overflow). When overflow occurs, the global variable errno is additionally set to PGTYPES_NUM_OVERFLOW.

int PGTYPESnumeric_to_decimal(numeric* src, decimal* dst)

Converts a numeric variable into a decimal variable.

This function converts the numeric value in the variable that src points to into a decimal variable that dst points to. The function returns 0 on success and –1 in case of error (or overflow). When overflow occurs, the global variable errno is additionally set to PGTYPES_NUM_OVERFLOW.

int PGTYPESnumeric_from_decimal(decimal* src, numeric* dst)

Converts a decimal variable into a numeric variable.

This function converts the decimal value in the variable that src points to into a numeric variable that dst points to. The function returns 0 on success and –1 in case of error (or overflow).

Examples

For details, see Examples.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback