Safe and correct way to convert REAL to Int
Hello, We use RFA 8.1 C++ api. We have a use case where we want to convert REAL type to int using DataBuffer. We accept the fact that doing this will result in data truncation. I can do it in two ways but what is the most accurate way to do it?
Assuming DataBuffer contains REAL type -
A. dataBuffer.getInt()
B. static_cast<int>(dataBuffer.getDouble());
Which one of the above is more accurate? Is there any other way to do this?
Answers
-
I just tried something and realized that following does not work correctly
dataBuffer.getInt()
0 -
Thank you for reaching out to us.
It could look like this:
write("\n%s\n", dataBuffer.getAsString().c_str()); write("%lld\n", dataBuffer.getInt()); write("%d\n", (int)round(dataBuffer.getDouble()));If you would like to get a round number, you can use the round method in <cmath>.
0 -
HI @Jirapongse When value is "45.110" then
dataBuffer.getInt()returns45110which is not expected in our case I guess.Also REAL64 can have exponent part, so how would it work in that case?
0 -
I used this code.
case DataBuffer::RealEnum: printf("\n%s\n", dataBuffer.getAsString().c_str()); printf("%lld\n", dataBuffer.getInt()); printf("%d\n", (int)round(dataBuffer.getDouble())); break;It returned the correct values.
2025 May 20 17:26:32.441 ST GMT+07:00 998C 8F08 594 TRACE <- Received MMT_MARKET_PRICE Update JPY=.
FieldList: standard data count = 2
FieldEntry [ 22] BID
45.110
45
45I am using rfa8.2.5.L3.
0 -
@Jirapongse can you cofirm if
round()is needed to handle IEEE754 binary floating point representation? So is it possible that when we have to convert REAL64 value12.0, it can be represented as11.9999999998after converting todoublefromREAL64? If so then I have to always useroundafter REAL to int conversion to get corrrect12value?0 -
The round() is not part of our library. You may need to find and check it online regarding IEEE754.
Moreover, you may need to run a lot of test cases to make sure that the real values can be converted to integer values properly.
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 37 Alpha
- 167 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 712 Datastream
- 1.5K DSS
- 638 Eikon COM
- 5.3K Eikon Data APIs
- 19 Electronic Trading
- 1 Generic FIX
- 7 Local Bank Node API
- 11 Trading API
- 3K Elektron
- 1.5K EMA
- 260 ETA
- 572 WebSocket API
- 42 FX Venues
- 16 FX Market Data
- 2 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 26 Messenger Bot
- 5 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 285 Open PermID
- 47 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 25 RDMS
- 2.3K Refinitiv Data Platform
- 19 CFS Bulk File/TM3
- 935 Refinitiv Data Platform Libraries
- 5 LSEG Due Diligence
- 1 LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 12 World-Check Customer Risk Screener
- World-Check On Demand
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 46 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 126 Open DACS
- 1.1K RFA
- 108 UPA
- 197 TREP Infrastructure
- 232 TRKD
- 925 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 106 Workspace SDK
- 11 Element Framework
- 5 Grid
- 19 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛