1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[俺得]10進固定小数点2桁を表示して遊ぶ。(printfバージョン)

Last updated at Posted at 2025-06-26

いろいろ注意

  • 過去ログを見よ
  • arduinoでの予定は、未定
  • 誰得、俺得
  • stm32系とesp32系は、printf文が使えるはず?

目的

  • 主に温度センサーのバイナリー値を変換して表示する

プログラム

  • オンラインコンパイラpaiza


#include <stdlib.h> // abs用

#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    int tmp; //10進固定小数点2桁(元を100倍した数)
    
    //tmp = 2525;
    //tmp = 25;
    //tmp = 0;
    //tmp = -25;
    tmp = -2525;

    //printf("%d\n",tmp); //debug
    
    //負の数の時で0から-100の時の処理
    if( (tmp < 0) & (tmp > (-100)) ){
        printf("-0.%02d\n",abs(tmp%100));
    } else {
        printf("%d.%02d\n",tmp/100,abs(tmp%100));
    }
    
}




-25.25

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?