Last active
July 13, 2016 10:23
-
-
Save peanutwolf/dc9b6c597a6195d5e747 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ValToAmount(char pdPriceStr[14], unsigned long int pdPrice) { | |
unsigned char iLen = 0; | |
char amountFormat[14] = { '0', '0', '.', '0', '0', '0', '.', '0', '0', '0', ',', '0', '0', '\0'}; | |
unsigned char pdPricePrime = 0; | |
memset(pdPriceStr, 0, NUMBER_OF_ITEMS(amountFormat)); | |
iLen = strlen(amountFormat); | |
pdPricePrime = pdPrice % 10; | |
pdPrice /= 10; | |
while ((pdPrice != 0 || pdPricePrime > 0) && iLen > 0){ | |
if (amountFormat[iLen - 1] == ',' || amountFormat[iLen - 1] == '.'){ | |
iLen--; | |
} | |
amountFormat[iLen - 1] = pdPricePrime + 0x30; | |
iLen--; | |
pdPricePrime = pdPrice % 10; | |
pdPrice /= 10; | |
} | |
for (iLen = 0; (amountFormat[iLen] == '0' || amountFormat[iLen] == '.') && iLen < 9; iLen++); | |
strcpy(pdPriceStr, &amountFormat[iLen]); | |
} | |
unsigned long int AmountToVal(const char pdPriceStr[14]){ | |
unsigned char iLen = 0; | |
unsigned char i = 0; | |
unsigned long int pdPrice = 0; | |
char pdPriceStrTmp[14]; | |
iLen = strlen(pdPriceStr); | |
strcpy(pdPriceStrTmp, pdPriceStr); | |
for (i = 0; i < iLen; i++){ | |
if (pdPriceStrTmp[i] == '.' || pdPriceStrTmp[i] == ','){ | |
strcpy(&pdPriceStrTmp[i], &pdPriceStrTmp[i+1]); | |
iLen--; | |
} | |
} | |
return pdPrice = atoi(pdPriceStrTmp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment